From c4dbf971fba9c845aba7d698bb62451099928b68 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Mon, 8 Feb 2010 12:02:54 +0000 Subject: [PATCH] author_notification field added. svn path=/plone.app.discussion/branches/notification/; revision=33867 --- plone/app/discussion/browser/comments.py | 11 ++++++----- plone/app/discussion/comment.py | 24 ++++++++++++++++++++++++ plone/app/discussion/interfaces.py | 2 ++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index 3b0fa84..8ad3925 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -19,6 +19,7 @@ from zope.viewlet.interfaces import IViewlet from z3c.form import form, field, button, interfaces, widget from z3c.form.browser.textarea import TextAreaWidget +from z3c.form.browser.checkbox import SingleCheckBoxFieldWidget from Products.Five.browser import BrowserView from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile @@ -55,19 +56,19 @@ class CommentForm(extensible.ExtensibleForm, form.Form): 'modification_date', 'author_username') + def updateFields(self): + self.fields['author_notification'].widgetFactory = SingleCheckBoxFieldWidget + self.move('author_notification', after='text') + def updateWidgets(self): super(CommentForm, self).updateWidgets() self.widgets['in_reply_to'].mode = interfaces.HIDDEN_MODE portal_membership = getToolByName(self.context, 'portal_membership') self.widgets['text'].addClass("autoresize") + self.widgets['author_notification'].label = _(u"") if not portal_membership.isAnonymousUser(): self.widgets['author_name'].mode = interfaces.HIDDEN_MODE self.widgets['author_email'].mode = interfaces.HIDDEN_MODE - # XXX: Since we are not using the author_email field in the - # current state, we hide it by default. But we keep the field for - # integrators or later use. - self.widgets['author_email'].mode = interfaces.HIDDEN_MODE - def updateActions(self): super(CommentForm, self).updateActions() diff --git a/plone/app/discussion/comment.py b/plone/app/discussion/comment.py index 7a39a8c..9a6cb61 100644 --- a/plone/app/discussion/comment.py +++ b/plone/app/discussion/comment.py @@ -61,6 +61,8 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable, author_name = None author_email = None + + author_notification = None # Note: we want to use zope.component.createObject() to instantiate # comments as far as possible. comment_id and __parent__ are set via @@ -126,3 +128,25 @@ def notify_content_object(obj, event): """ content_obj = aq_parent(aq_parent(obj)) content_obj.reindexObject(idxs=('total_comments', 'last_comment_date', 'commentators',)) + +def notify_user(obj, event): + """Tell the user when a comment is added + """ + acl_users = getToolByName(obj, 'acl_users') + mail_host = getToolByName(obj, 'MailHost') + portal_url = getToolByName(obj, 'portal_url') + + portal = portal_url.getPortalObject() + sender = portal.getProperty('email_from_address') + + if not sender: + return + + subject = "Is this you?" + message = "A presenter called %s was added here %s" % (obj.title, obj.absolute_url(),) + + matching_users = acl_users.searchUsers(fullname=obj.title) + for user_info in matching_users: + email = user_info.get('email', None) + if email is not None: + mail_host.secureSend(message, email, sender, subject) \ No newline at end of file diff --git a/plone/app/discussion/interfaces.py b/plone/app/discussion/interfaces.py index 08f7b73..df06665 100644 --- a/plone/app/discussion/interfaces.py +++ b/plone/app/discussion/interfaces.py @@ -171,6 +171,8 @@ class IComment(Interface): # for anonymous comments only, set to None for logged in comments author_name = schema.TextLine(title=_(u"Name"), required=False) author_email = schema.TextLine(title=_(u"Email"), required=False) + + author_notification = schema.Bool(title=_("Notify me of new posts via email"), required=False) title = schema.TextLine(title=_(u"Subject"))