comment system extensions: make comments stateful as basis for moderated comments
This commit is contained in:
		
							parent
							
								
									6e901de066
								
							
						
					
					
						commit
						8ce1eb7222
					
				
					 5 changed files with 63 additions and 8 deletions
				
			
		|  | @ -45,6 +45,9 @@ to assign comments to this document. | ||||||
|   >>> home = views['home'] |   >>> home = views['home'] | ||||||
|   >>> home.target = resources['d001.txt'] |   >>> home.target = resources['d001.txt'] | ||||||
| 
 | 
 | ||||||
|  |   >>> from loops.organize.comment.base import commentStates | ||||||
|  |   >>> component.provideUtility(commentStates(), name='organize.commentStates') | ||||||
|  | 
 | ||||||
| Creating comments | Creating comments | ||||||
| ----------------- | ----------------- | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| # | # | ||||||
| #  Copyright (c) 2008 Helmut Merz helmutm@cy55.de | #  Copyright (c) 2014 Helmut Merz helmutm@cy55.de | ||||||
| # | # | ||||||
| #  This program is free software; you can redistribute it and/or modify | #  This program is free software; you can redistribute it and/or modify | ||||||
| #  it under the terms of the GNU General Public License as published by | #  it under the terms of the GNU General Public License as published by | ||||||
|  | @ -18,24 +18,46 @@ | ||||||
| 
 | 
 | ||||||
| """ | """ | ||||||
| Base classes for comments/discussions. | Base classes for comments/discussions. | ||||||
| 
 |  | ||||||
| $Id$ |  | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| from zope.component import adapts | from zope.component import adapts | ||||||
| from zope.interface import implements | from zope.interface import implementer, implements | ||||||
| 
 | 
 | ||||||
|  | from cybertools.stateful.definition import StatesDefinition | ||||||
|  | from cybertools.stateful.definition import State, Transition | ||||||
|  | from cybertools.stateful.interfaces import IStatesDefinition | ||||||
| from cybertools.tracking.btree import Track | from cybertools.tracking.btree import Track | ||||||
| from cybertools.tracking.interfaces import ITrackingStorage | from cybertools.tracking.interfaces import ITrackingStorage | ||||||
| from cybertools.tracking.comment.interfaces import IComment | from loops.organize.comment.interfaces import IComment | ||||||
|  | from loops.organize.stateful.base import Stateful | ||||||
| from loops import util | from loops import util | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Comment(Track): | @implementer(IStatesDefinition) | ||||||
|  | def commentStates(): | ||||||
|  |     return StatesDefinition('commentStates', | ||||||
|  |         State('new', 'new', ('accept', 'reject'), color='red'), | ||||||
|  |         State('public', 'public', ('retract', 'reject'), color='green'), | ||||||
|  |         State('rejected', 'rejected', ('accept'), color='grey'), | ||||||
|  |         Transition('accept', 'accept', 'public'), | ||||||
|  |         Transition('reject', 'reject', 'rejected'), | ||||||
|  |         Transition('retract', 'retract', 'new'), | ||||||
|  |         initialState='new') | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class Comment(Stateful, Track): | ||||||
| 
 | 
 | ||||||
|     implements(IComment) |     implements(IComment) | ||||||
| 
 | 
 | ||||||
|  |     metadata_attributes = Track.metadata_attributes + ('state',) | ||||||
|  |     index_attributes = metadata_attributes | ||||||
|     typeName = 'Comment' |     typeName = 'Comment' | ||||||
|  |     typeInterface = IComment | ||||||
|  |     statesDefinition = 'organize.commentStates' | ||||||
| 
 | 
 | ||||||
|     contentType = 'text/restructured' |     contentType = 'text/restructured' | ||||||
| 
 | 
 | ||||||
|  |     def __init__(self, taskId, runId, userName, data): | ||||||
|  |         super(Comment, self).__init__(taskId, runId, userName, data) | ||||||
|  |         self.state = self.getState()    # make initial state persistent | ||||||
|  | 
 | ||||||
|  |  | ||||||
|  | @ -12,6 +12,10 @@ | ||||||
|              set_schema="cybertools.tracking.comment.interfaces.IComment" /> |              set_schema="cybertools.tracking.comment.interfaces.IComment" /> | ||||||
|   </zope:class> |   </zope:class> | ||||||
| 
 | 
 | ||||||
|  |   <zope:utility | ||||||
|  |         factory="loops.organize.comment.base.commentStates" | ||||||
|  |         name="organize.commentStates" /> | ||||||
|  | 
 | ||||||
|   <!-- views --> |   <!-- views --> | ||||||
| 
 | 
 | ||||||
|   <browser:page |   <browser:page | ||||||
|  |  | ||||||
							
								
								
									
										26
									
								
								organize/comment/interfaces.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								organize/comment/interfaces.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | ||||||
|  | # | ||||||
|  | #  Copyright (c) 2014 Helmut Merz helmutm@cy55.de | ||||||
|  | # | ||||||
|  | #  This program is free software; you can redistribute it and/or modify | ||||||
|  | #  it under the terms of the GNU General Public License as published by | ||||||
|  | #  the Free Software Foundation; either version 2 of the License, or | ||||||
|  | #  (at your option) any later version. | ||||||
|  | # | ||||||
|  | #  This program is distributed in the hope that it will be useful, | ||||||
|  | #  but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  | #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  | #  GNU General Public License for more details. | ||||||
|  | # | ||||||
|  | #  You should have received a copy of the GNU General Public License | ||||||
|  | #  along with this program; if not, write to the Free Software | ||||||
|  | #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | ||||||
|  | # | ||||||
|  | 
 | ||||||
|  | """ | ||||||
|  | Interface definitions for comments - discussions - forums. | ||||||
|  | """ | ||||||
|  | 
 | ||||||
|  | from zope.interface import Interface, Attribute | ||||||
|  | from zope import schema | ||||||
|  | 
 | ||||||
|  | from cybertools.tracking.comment.interfaces import IComment | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| # | # | ||||||
| #  Copyright (c) 2013 Helmut Merz helmutm@cy55.de | #  Copyright (c) 2014 Helmut Merz helmutm@cy55.de | ||||||
| # | # | ||||||
| #  This program is free software; you can redistribute it and/or modify | #  This program is free software; you can redistribute it and/or modify | ||||||
| #  it under the terms of the GNU General Public License as published by | #  it under the terms of the GNU General Public License as published by | ||||||
|  | @ -86,7 +86,7 @@ class BaseTrackView(TrackView): | ||||||
| 
 | 
 | ||||||
|     def getMetadataTarget(self, key): |     def getMetadataTarget(self, key): | ||||||
|         value = self.metadata.get(key) |         value = self.metadata.get(key) | ||||||
|         if value.isdigit(): |         if value and value.isdigit(): | ||||||
|             obj = util.getObjectForUid(value) |             obj = util.getObjectForUid(value) | ||||||
|             if obj is not None: |             if obj is not None: | ||||||
|                 url = ('%s/@@SelectedManagementView.html' % |                 url = ('%s/@@SelectedManagementView.html' % | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue