2016-02-05 01:39:53 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
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
|
|
|
|
2014-04-17 17:38:44 +02:00
|
|
|
class BaseSubstitution(object):
|
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):
|
|
|
|
super(CommentSubstitution, self).__init__(context, **kwargs)
|
|
|
|
|
|
|
|
@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"""
|
|
|
|
|
|
|
|
category = _(u"Comments")
|
|
|
|
description = _(u"Comment id")
|
2014-04-17 17:38:44 +02:00
|
|
|
|
|
|
|
def safe_call(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Safe call"""
|
|
|
|
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):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Comment text"""
|
|
|
|
|
|
|
|
category = _(u"Comments")
|
|
|
|
description = _(u"Comment text")
|
2014-04-17 17:38:44 +02:00
|
|
|
|
|
|
|
def safe_call(self):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Safe call"""
|
|
|
|
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):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Comment author user name string substitution"""
|
|
|
|
|
|
|
|
category = _(u"Comments")
|
|
|
|
description = _(u"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"""
|
|
|
|
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):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Comment author full name string substitution"""
|
|
|
|
|
|
|
|
category = _(u"Comments")
|
|
|
|
description = _(u"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"""
|
|
|
|
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):
|
2022-05-01 23:14:09 +02:00
|
|
|
"""Comment author email string substitution"""
|
|
|
|
|
|
|
|
category = _(u"Comments")
|
|
|
|
description = _(u"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"""
|
|
|
|
return getattr(self.comment, "author_email", u"")
|