plone.app.discussion/plone/app/discussion/events.py
Alin Voinea 13830715a7 Add custom content rules string substitutions
- Add content rules string substitutions for comment:
  - id
  - text
  - author email
  - author user name
  - author full name
2014-04-18 16:36:06 +03:00

52 lines
1.7 KiB
Python

""" Custom discussion events
"""
from zope.interface import implements
from plone.app.discussion.interfaces import IComment
from plone.app.discussion.interfaces import IDiscussionEvent
from plone.app.discussion.interfaces import ICommentAddedEvent
from plone.app.discussion.interfaces import ICommentRemovedEvent
from plone.app.discussion.interfaces import IReplyAddedEvent
from plone.app.discussion.interfaces import IReplyRemovedEvent
class DiscussionEvent(object):
""" Custom event
"""
implements(IDiscussionEvent)
def __init__(self, context, comment, **kwargs):
self.object = context
self.comment = comment
for key, value in kwargs.items():
setattr(self, key, value)
# Add comment on session to easily define content-rules dynamic strings
sdm = getattr(context, 'session_data_manager', None)
session = sdm.getSessionData(create=True) if sdm else None
if session:
sessionComment = dict(
(field, getattr(comment, field, None)) for field in IComment
if not field.startswith('_')
)
session.set('comment', sessionComment)
class CommentAddedEvent(DiscussionEvent):
""" Event to be triggered when a Comment is added
"""
implements(ICommentAddedEvent)
class CommentRemovedEvent(DiscussionEvent):
""" Event to be triggered when a Comment is removed
"""
implements(ICommentRemovedEvent)
class ReplyAddedEvent(DiscussionEvent):
""" Event to be triggered when a Comment reply is added
"""
implements(IReplyAddedEvent)
class ReplyRemovedEvent(DiscussionEvent):
""" Event to be triggered when a Comment reply is removed
"""
implements(IReplyRemovedEvent)