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.
This commit is contained in:
parent
4343197209
commit
14d4382ca6
@ -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.
|
||||
|
@ -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
|
||||
"""
|
||||
|
@ -2,9 +2,9 @@
|
||||
xmlns="http://namespaces.zope.org/zope"
|
||||
xmlns:zcml="http://namespaces.zope.org/zcml">
|
||||
|
||||
<!-- Content Rules events -->
|
||||
<configure zcml:condition="installed plone.contentrules">
|
||||
|
||||
<!-- Content Rules events -->
|
||||
<interface
|
||||
interface="plone.app.discussion.interfaces.ICommentAddedEvent"
|
||||
type="plone.contentrules.rule.interfaces.IRuleEventType"
|
||||
@ -32,9 +32,9 @@
|
||||
</configure>
|
||||
|
||||
|
||||
<!-- Content rules subscribers -->
|
||||
<configure zcml:condition="installed plone.app.contentrules">
|
||||
|
||||
<!-- Content rules subscribers -->
|
||||
<subscriber
|
||||
for="plone.app.discussion.interfaces.ICommentAddedEvent"
|
||||
handler=".contentrules.execute_comment"
|
||||
@ -55,259 +55,6 @@
|
||||
handler=".contentrules.execute_comment"
|
||||
/>
|
||||
|
||||
<!-- Content rules string substitutions -->
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentUrlSubstitution"
|
||||
name="absolute_url"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentUrlSubstitution"
|
||||
name="url"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentParentUrlSubstitution"
|
||||
name="parent_url"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentIdSubstitution"
|
||||
name="id"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentTitleSubstitution"
|
||||
name="title"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentParentTitleSubstitution"
|
||||
name="parent_title"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentDescriptionSubstitution"
|
||||
name="description"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentTypeSubstitution"
|
||||
name="type"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentReviewStateSubstitution"
|
||||
name="review_state"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentReviewStateTitleSubstitution"
|
||||
name="review_state_title"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentCreatedSubstitution"
|
||||
name="created"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentEffectiveSubstitution"
|
||||
name="effective"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentExpiresSubstitution"
|
||||
name="expires"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentModifiedSubstitution"
|
||||
name="modified"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentCreatorsSubstitution"
|
||||
name="creators"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentContributorsSubstitution"
|
||||
name="contributors"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentSubjectSubstitution"
|
||||
name="subject"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentSubjectSubstitution"
|
||||
name="keywords"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentFormatSubstitution"
|
||||
name="format"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentLanguageSubstitution"
|
||||
name="language"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentRightsSubstitution"
|
||||
name="rights"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentIdentifierSubstitution"
|
||||
name="identifier"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentOwnerEmailSubstitution"
|
||||
name="owner_emails"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentReviewerEmailSubstitution"
|
||||
name="reviewer_emails"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentReaderEmailSubstitution"
|
||||
name="reader_emails"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentEditorEmailSubstitution"
|
||||
name="editor_emails"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentContributorEmailSubstitution"
|
||||
name="contributor_emails"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentManagerEmailSubstitution"
|
||||
name="manager_emails"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentMemberEmailSubstitution"
|
||||
name="member_emails"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentUserEmailSubstitution"
|
||||
name="user_email"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentUserFullNameSubstitution"
|
||||
name="user_fullname"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentUserIdSubstitution"
|
||||
name="user_id"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentLastChangeCommentSubstitution"
|
||||
name="change_comment"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentLastChangeTitleSubstitution"
|
||||
name="change_title"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentLastChangeTypeSubstitution"
|
||||
name="change_type"
|
||||
/>
|
||||
|
||||
<adapter
|
||||
for="plone.app.discussion.interfaces.IComment"
|
||||
provides="plone.stringinterp.interfaces.IStringSubstitution"
|
||||
factory=".contentrules.CommentLastChangeActorIdSubstitution"
|
||||
name="change_authorid"
|
||||
/>
|
||||
|
||||
</configure>
|
||||
|
||||
</configure>
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user