author_notification field added.

svn path=/plone.app.discussion/branches/notification/; revision=33867
This commit is contained in:
Timo Stollenwerk 2010-02-08 12:02:54 +00:00
parent 23eeb041aa
commit c4dbf971fb
3 changed files with 32 additions and 5 deletions

View File

@ -19,6 +19,7 @@ from zope.viewlet.interfaces import IViewlet
from z3c.form import form, field, button, interfaces, widget from z3c.form import form, field, button, interfaces, widget
from z3c.form.browser.textarea import TextAreaWidget from z3c.form.browser.textarea import TextAreaWidget
from z3c.form.browser.checkbox import SingleCheckBoxFieldWidget
from Products.Five.browser import BrowserView from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
@ -55,19 +56,19 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
'modification_date', 'modification_date',
'author_username') 'author_username')
def updateFields(self):
self.fields['author_notification'].widgetFactory = SingleCheckBoxFieldWidget
self.move('author_notification', after='text')
def updateWidgets(self): def updateWidgets(self):
super(CommentForm, self).updateWidgets() super(CommentForm, self).updateWidgets()
self.widgets['in_reply_to'].mode = interfaces.HIDDEN_MODE self.widgets['in_reply_to'].mode = interfaces.HIDDEN_MODE
portal_membership = getToolByName(self.context, 'portal_membership') portal_membership = getToolByName(self.context, 'portal_membership')
self.widgets['text'].addClass("autoresize") self.widgets['text'].addClass("autoresize")
self.widgets['author_notification'].label = _(u"")
if not portal_membership.isAnonymousUser(): if not portal_membership.isAnonymousUser():
self.widgets['author_name'].mode = interfaces.HIDDEN_MODE self.widgets['author_name'].mode = interfaces.HIDDEN_MODE
self.widgets['author_email'].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): def updateActions(self):
super(CommentForm, self).updateActions() super(CommentForm, self).updateActions()

View File

@ -61,6 +61,8 @@ class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
author_name = None author_name = None
author_email = None author_email = None
author_notification = None
# Note: we want to use zope.component.createObject() to instantiate # Note: we want to use zope.component.createObject() to instantiate
# comments as far as possible. comment_id and __parent__ are set via # 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 = aq_parent(aq_parent(obj))
content_obj.reindexObject(idxs=('total_comments', 'last_comment_date', 'commentators',)) 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)

View File

@ -171,6 +171,8 @@ class IComment(Interface):
# for anonymous comments only, set to None for logged in comments # for anonymous comments only, set to None for logged in comments
author_name = schema.TextLine(title=_(u"Name"), required=False) author_name = schema.TextLine(title=_(u"Name"), required=False)
author_email = schema.TextLine(title=_(u"Email"), 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")) title = schema.TextLine(title=_(u"Subject"))