comment system extensions: make comments stateful as basis for moderated comments

This commit is contained in:
Helmut Merz 2014-02-28 17:11:22 +01:00
parent 6e901de066
commit 8ce1eb7222
5 changed files with 63 additions and 8 deletions

View file

@ -45,6 +45,9 @@ to assign comments to this document.
>>> home = views['home']
>>> home.target = resources['d001.txt']
>>> from loops.organize.comment.base import commentStates
>>> component.provideUtility(commentStates(), name='organize.commentStates')
Creating comments
-----------------

View file

@ -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
# it under the terms of the GNU General Public License as published by
@ -18,24 +18,46 @@
"""
Base classes for comments/discussions.
$Id$
"""
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.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
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)
metadata_attributes = Track.metadata_attributes + ('state',)
index_attributes = metadata_attributes
typeName = 'Comment'
typeInterface = IComment
statesDefinition = 'organize.commentStates'
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

View file

@ -12,6 +12,10 @@
set_schema="cybertools.tracking.comment.interfaces.IComment" />
</zope:class>
<zope:utility
factory="loops.organize.comment.base.commentStates"
name="organize.commentStates" />
<!-- views -->
<browser:page

View 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

View file

@ -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
# it under the terms of the GNU General Public License as published by
@ -86,7 +86,7 @@ class BaseTrackView(TrackView):
def getMetadataTarget(self, key):
value = self.metadata.get(key)
if value.isdigit():
if value and value.isdigit():
obj = util.getObjectForUid(value)
if obj is not None:
url = ('%s/@@SelectedManagementView.html' %