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:
|
2022-05-01 23:14:09 +02:00
|
|
|
|
2022-05-01 23:14:41 +02:00
|
|
|
class BaseSubstitution:
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Fallback class if plone.stringinterp is not available"""
|
2016-02-05 01:39:53 +01:00
|
|
|
|
2014-04-17 17:38:44 +02:00
|
|
|
def __init__(self, context, **kwargs):
|
|
|
|
self.context = context
|
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
|
2014-04-17 17:38:44 +02:00
|
|
|
try:
|
|
|
|
from plone.app.contentrules.handlers import execute
|
|
|
|
except ImportError:
|
2022-05-01 23:14:09 +02:00
|
|
|
|
2016-06-10 02:14:45 +02:00
|
|
|
def execute(context, event):
|
|
|
|
return False
|
2014-04-17 17:38:44 +02:00
|
|
|
|
2014-04-16 17:54:19 +02:00
|
|
|
|
|
|
|
def execute_comment(event):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Execute comment content rules"""
|
2014-04-16 17:54:19 +02:00
|
|
|
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):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Comment string substitution"""
|
2016-02-05 01:39:53 +01:00
|
|
|
|
2014-04-17 17:38:44 +02:00
|
|
|
def __init__(self, context, **kwargs):
|
2022-05-01 23:14:41 +02:00
|
|
|
super().__init__(context, **kwargs)
|
2014-04-17 17:38:44 +02:00
|
|
|
|
|
|
|
@property
|
2014-09-20 14:14:19 +02:00
|
|
|
def event(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""event that triggered the content rule"""
|
|
|
|
return self.context.REQUEST.get("event")
|
2014-04-17 17:38:44 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def comment(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""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):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Comment id string substitution"""
|
|
|
|
|
2022-05-01 23:14:41 +02:00
|
|
|
category = _("Comments")
|
|
|
|
description = _("Comment id")
|
2014-04-17 17:38:44 +02:00
|
|
|
|
|
|
|
def safe_call(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Safe call"""
|
2022-05-01 23:14:41 +02:00
|
|
|
return getattr(self.comment, "comment_id", "")
|
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):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Comment text"""
|
|
|
|
|
2022-05-01 23:14:41 +02:00
|
|
|
category = _("Comments")
|
|
|
|
description = _("Comment text")
|
2014-04-17 17:38:44 +02:00
|
|
|
|
|
|
|
def safe_call(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Safe call"""
|
2022-05-01 23:14:41 +02:00
|
|
|
return getattr(self.comment, "text", "")
|
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):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Comment author user name string substitution"""
|
|
|
|
|
2022-05-01 23:14:41 +02:00
|
|
|
category = _("Comments")
|
|
|
|
description = _("Comment author user name")
|
2014-04-17 17:38:44 +02:00
|
|
|
|
|
|
|
def safe_call(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Safe call"""
|
2022-05-01 23:14:41 +02:00
|
|
|
return getattr(self.comment, "author_username", "")
|
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):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Comment author full name string substitution"""
|
|
|
|
|
2022-05-01 23:14:41 +02:00
|
|
|
category = _("Comments")
|
|
|
|
description = _("Comment author full name")
|
2014-04-17 17:38:44 +02:00
|
|
|
|
|
|
|
def safe_call(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Safe call"""
|
2022-05-01 23:14:41 +02:00
|
|
|
return getattr(self.comment, "author_name", "")
|
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):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Comment author email string substitution"""
|
|
|
|
|
2022-05-01 23:14:41 +02:00
|
|
|
category = _("Comments")
|
|
|
|
description = _("Comment author email")
|
2014-04-17 17:38:44 +02:00
|
|
|
|
|
|
|
def safe_call(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Safe call"""
|
2022-05-01 23:14:41 +02:00
|
|
|
return getattr(self.comment, "author_email", "")
|