diff --git a/plone/app/discussion/comment.py b/plone/app/discussion/comment.py index 97f2b17..917646c 100644 --- a/plone/app/discussion/comment.py +++ b/plone/app/discussion/comment.py @@ -235,6 +235,7 @@ def notify_content_object(obj, event): 'last_comment_date', 'commentators')) + def notify_content_object_deleted(obj, event): """Remove all comments of a content object when the content object has been deleted. @@ -244,6 +245,7 @@ def notify_content_object_deleted(obj, event): while conversation: del conversation[conversation.keys()[0]] + def notify_comment_added(obj, event): """ Notify custom discussion events when a comment is added or replied """ @@ -253,6 +255,7 @@ def notify_comment_added(obj, event): return notify(ReplyAddedEvent(context, obj)) return notify(CommentAddedEvent(context, obj)) + def notify_comment_removed(obj, event): """ Notify custom discussion events when a comment or reply is removed """ @@ -262,6 +265,7 @@ def notify_comment_removed(obj, event): return notify(ReplyRemovedEvent(context, obj)) return notify(CommentRemovedEvent(context, obj)) + def notify_content_object_moved(obj, event): """Update all comments of a content object that has been moved. """ diff --git a/plone/app/discussion/contentrules.py b/plone/app/discussion/contentrules.py index dfa00fc..8dc082b 100644 --- a/plone/app/discussion/contentrules.py +++ b/plone/app/discussion/contentrules.py @@ -23,6 +23,7 @@ def execute_comment(event): """ execute(event.object, event) + class CommentSubstitution(BaseSubstitution): """ Comment string substitution """ @@ -41,6 +42,7 @@ class CommentSubstitution(BaseSubstitution): """ return self.event.comment + class Id(CommentSubstitution): """ Comment id string substitution """ @@ -52,6 +54,7 @@ class Id(CommentSubstitution): """ return getattr(self.comment, 'comment_id', u'') + class Text(CommentSubstitution): """ Comment text """ @@ -63,6 +66,7 @@ class Text(CommentSubstitution): """ return getattr(self.comment, 'text', u'') + class AuthorUserName(CommentSubstitution): """ Comment author user name string substitution """ @@ -74,6 +78,7 @@ class AuthorUserName(CommentSubstitution): """ return getattr(self.comment, 'author_username', u'') + class AuthorFullName(CommentSubstitution): """ Comment author full name string substitution """ @@ -85,6 +90,7 @@ class AuthorFullName(CommentSubstitution): """ return getattr(self.comment, 'author_name', u'') + class AuthorEmail(CommentSubstitution): """ Comment author email string substitution """ diff --git a/plone/app/discussion/events.py b/plone/app/discussion/events.py index 2ec918b..aefe2ab 100644 --- a/plone/app/discussion/events.py +++ b/plone/app/discussion/events.py @@ -24,21 +24,25 @@ class DiscussionEvent(object): request = context.REQUEST request.set('event', self) + 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 """ diff --git a/plone/app/discussion/interfaces.py b/plone/app/discussion/interfaces.py index 20b6afe..2d15935 100644 --- a/plone/app/discussion/interfaces.py +++ b/plone/app/discussion/interfaces.py @@ -371,22 +371,27 @@ class ICommentingTool(Interface): # Custom events # + class IDiscussionEvent(IObjectEvent): """ Discussion custom event """ + class ICommentAddedEvent(IDiscussionEvent): """ Comment added """ + class ICommentRemovedEvent(IDiscussionEvent): """ Comment removed """ + class IReplyAddedEvent(IDiscussionEvent): """ Comment reply added """ + class IReplyRemovedEvent(IDiscussionEvent): """ Comment reply removed """ diff --git a/plone/app/discussion/tests/test_contentrules.py b/plone/app/discussion/tests/test_contentrules.py index 51e9254..8d28bf0 100644 --- a/plone/app/discussion/tests/test_contentrules.py +++ b/plone/app/discussion/tests/test_contentrules.py @@ -44,7 +44,6 @@ class CommentContentRulesTest(unittest.TestCase): conversation = IConversation(self.document) conversation.addComment(comment) - def testEventTypesMarked(self): self.assertTrue(IRuleEventType.providedBy(ICommentAddedEvent)) self.assertTrue(IRuleEventType.providedBy(ICommentRemovedEvent)) diff --git a/plone/app/discussion/tests/test_events.py b/plone/app/discussion/tests/test_events.py index 431df14..e72de0c 100644 --- a/plone/app/discussion/tests/test_events.py +++ b/plone/app/discussion/tests/test_events.py @@ -27,20 +27,29 @@ class EventsRegistry(object): # # Fake event handlers # + + def comment_added(doc, evt): EventsRegistry.commentAdded = True + def comment_removed(doc, evt): EventsRegistry.commentRemoved = True + def reply_added(doc, evt): EventsRegistry.replyAdded = True + def reply_removed(doc, evt): EventsRegistry.replyRemoved = True + + # # Tests # + + class CommentEventsTest(unittest.TestCase): """ Test custom comments events """