2014-04-16 17:54:19 +02:00
|
|
|
""" Content rules handlers
|
|
|
|
"""
|
2015-11-05 00:26:49 +01:00
|
|
|
from plone.app.discussion import _
|
2014-04-17 17:38:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
from plone.stringinterp.adapters import BaseSubstitution
|
|
|
|
except ImportError:
|
|
|
|
class BaseSubstitution(object):
|
|
|
|
""" Fallback class if plone.stringinterp is not available
|
|
|
|
"""
|
|
|
|
def __init__(self, context, **kwargs):
|
|
|
|
self.context = context
|
|
|
|
|
|
|
|
try:
|
|
|
|
from plone.app.contentrules.handlers import execute
|
|
|
|
except ImportError:
|
|
|
|
execute = lambda context, event: False
|
|
|
|
|
2014-04-16 17:54:19 +02:00
|
|
|
|
|
|
|
def execute_comment(event):
|
|
|
|
""" Execute comment content rules
|
|
|
|
"""
|
|
|
|
execute(event.object, event)
|
2014-04-17 17:38:44 +02:00
|
|
|
|
2015-05-03 08:22:51 +02:00
|
|
|
|
2014-04-17 17:38:44 +02:00
|
|
|
class CommentSubstitution(BaseSubstitution):
|
|
|
|
""" Comment string substitution
|
|
|
|
"""
|
|
|
|
def __init__(self, context, **kwargs):
|
|
|
|
super(CommentSubstitution, self).__init__(context, **kwargs)
|
|
|
|
|
|
|
|
@property
|
2014-09-20 14:14:19 +02:00
|
|
|
def event(self):
|
|
|
|
""" event that triggered the content rule
|
2014-04-17 17:38:44 +02:00
|
|
|
"""
|
2014-09-20 14:14:19 +02:00
|
|
|
return self.context.REQUEST.get('event')
|
2014-04-17 17:38:44 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def comment(self):
|
|
|
|
""" Get changed inline comment
|
|
|
|
"""
|
2014-09-20 14:14:19 +02:00
|
|
|
return self.event.comment
|
2014-04-17 17:38:44 +02:00
|
|
|
|
2015-05-03 08:22:51 +02:00
|
|
|
|
2014-04-17 17:38:44 +02:00
|
|
|
class Id(CommentSubstitution):
|
|
|
|
""" Comment id string substitution
|
|
|
|
"""
|
|
|
|
category = _(u'Comments')
|
|
|
|
description = _(u'Comment id')
|
|
|
|
|
|
|
|
def safe_call(self):
|
|
|
|
""" Safe call
|
|
|
|
"""
|
2014-09-20 14:14:19 +02:00
|
|
|
return getattr(self.comment, 'comment_id', u'')
|
2014-04-17 17:38:44 +02:00
|
|
|
|
2015-05-03 08:22:51 +02:00
|
|
|
|
2014-04-17 17:38:44 +02:00
|
|
|
class Text(CommentSubstitution):
|
|
|
|
""" Comment text
|
|
|
|
"""
|
|
|
|
category = _(u'Comments')
|
|
|
|
description = _(u'Comment text')
|
|
|
|
|
|
|
|
def safe_call(self):
|
|
|
|
""" Safe call
|
|
|
|
"""
|
2014-09-20 14:14:19 +02:00
|
|
|
return getattr(self.comment, 'text', u'')
|
2014-04-17 17:38:44 +02:00
|
|
|
|
2015-05-03 08:22:51 +02:00
|
|
|
|
2014-04-17 17:38:44 +02:00
|
|
|
class AuthorUserName(CommentSubstitution):
|
|
|
|
""" Comment author user name string substitution
|
|
|
|
"""
|
|
|
|
category = _(u'Comments')
|
|
|
|
description = _(u'Comment author user name')
|
|
|
|
|
|
|
|
def safe_call(self):
|
|
|
|
""" Safe call
|
|
|
|
"""
|
2014-09-20 14:14:19 +02:00
|
|
|
return getattr(self.comment, 'author_username', u'')
|
2014-04-17 17:38:44 +02:00
|
|
|
|
2015-05-03 08:22:51 +02:00
|
|
|
|
2014-04-17 17:38:44 +02:00
|
|
|
class AuthorFullName(CommentSubstitution):
|
|
|
|
""" Comment author full name string substitution
|
|
|
|
"""
|
|
|
|
category = _(u'Comments')
|
|
|
|
description = _(u'Comment author full name')
|
|
|
|
|
|
|
|
def safe_call(self):
|
|
|
|
""" Safe call
|
|
|
|
"""
|
2014-09-20 14:14:19 +02:00
|
|
|
return getattr(self.comment, 'author_name', u'')
|
2014-04-17 17:38:44 +02:00
|
|
|
|
2015-05-03 08:22:51 +02:00
|
|
|
|
2014-04-17 17:38:44 +02:00
|
|
|
class AuthorEmail(CommentSubstitution):
|
|
|
|
""" Comment author email string substitution
|
|
|
|
"""
|
|
|
|
category = _(u'Comments')
|
|
|
|
description = _(u'Comment author email')
|
|
|
|
|
|
|
|
def safe_call(self):
|
|
|
|
""" Safe call
|
|
|
|
"""
|
2014-09-20 14:14:19 +02:00
|
|
|
return getattr(self.comment, 'author_email', u'')
|