From 14d4382ca6664d5136abc27097279ce42f62a452 Mon Sep 17 00:00:00 2001 From: Alin Voinea Date: Thu, 17 Apr 2014 14:57:41 +0300 Subject: [PATCH] Use commented object as context instead of comment within event trigger - In order this to work with plone.contentrules use commented object as the main context within custom discussion events and add comment as the second parameter. --- plone/app/discussion/comment.py | 12 +- plone/app/discussion/contentrules.py | 32 --- plone/app/discussion/contentrules.zcml | 257 +------------------------ plone/app/discussion/events.py | 3 +- 4 files changed, 12 insertions(+), 292 deletions(-) diff --git a/plone/app/discussion/comment.py b/plone/app/discussion/comment.py index c9e7077..bf41967 100644 --- a/plone/app/discussion/comment.py +++ b/plone/app/discussion/comment.py @@ -250,16 +250,20 @@ def notify_content_object_deleted(obj, event): def notify_comment_added(obj, event): """ Notify custom discussion events when a comment is added or replied """ + conversation = aq_parent(obj) + context = aq_parent(conversation) if getattr(obj, 'in_reply_to', None): - return notify(ReplyAddedEvent(obj)) - return notify(CommentAddedEvent(obj)) + 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 """ + conversation = aq_parent(obj) + context = aq_parent(conversation) if getattr(obj, 'in_reply_to', None): - return notify(ReplyRemovedEvent(obj)) - return notify(CommentRemovedEvent(obj)) + 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 eb46890..155c8c1 100644 --- a/plone/app/discussion/contentrules.py +++ b/plone/app/discussion/contentrules.py @@ -8,35 +8,3 @@ def execute_comment(event): """ Execute comment content rules """ execute(event.object, event) - -# -# String interp for comment's content rules -# -class Mixin(object): - """ Override context - """ - @property - def context(self): - """ Getter - """ - conversation = aq_parent(self._context) - return aq_parent(conversation) - - @context.setter - def context(self, value): - """ Setter - """ - self._context = value - - -class CommentUrlSubstitution(adapters.UrlSubstitution, Mixin): - """ Override context to be used for URL substitution - """ - -class CommentParentUrlSubstitution(adapters.ParentUrlSubstitution, Mixin): - """ Override context to be used for Parent URL substitution - """ - -class CommentIdSubstitution(adapters.IdSubstitution, Mixin): - """ Override context to be used for Id substitution - """ diff --git a/plone/app/discussion/contentrules.zcml b/plone/app/discussion/contentrules.zcml index b7f0353..8b8edc6 100644 --- a/plone/app/discussion/contentrules.zcml +++ b/plone/app/discussion/contentrules.zcml @@ -2,9 +2,9 @@ xmlns="http://namespaces.zope.org/zope" xmlns:zcml="http://namespaces.zope.org/zcml"> + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/plone/app/discussion/events.py b/plone/app/discussion/events.py index ec60da0..31253b7 100644 --- a/plone/app/discussion/events.py +++ b/plone/app/discussion/events.py @@ -12,8 +12,9 @@ class DiscussionEvent(object): """ implements(IDiscussionEvent) - def __init__(self, context, **kwargs): + def __init__(self, context, comment, **kwargs): self.object = context + self.comment = comment for key, value in kwargs.items(): setattr(self, key, value)