def NotificationHandler(event): """The Notification Handler receives a Notification event and calls the Notifier with the required attributes. """ obj = event.obj comment = event.comment try: notifier = INotifier(obj) except TypeError: return if event.action is None: action = _(u"label_send_notification", default=u"Send Notification") else: action = event.action if event.actor is None: portal_state = getMultiAdapter((obj, obj.REQUEST), name=u'plone_portal_state') actor = portal_state.member().getId() else: actor = event.actor if event.time is None: time = DateTime() else: time = event.time notifier(kwargs=dict(action=action, comment=comment, actor=actor, time=time))
def object_edited(object_, event): # Do nothing if send notification checkbox wasn't checked. if not object_.REQUEST.get('sendNotification', False): return sp = getToolByName(object_, 'portal_properties').site_properties use_view_action = object_.Type() in sp.getProperty( 'typesUseViewActionInListings', ()) # XXXXXXXXX handle groups add_group_members(object_, 'to_list') add_group_members(object_, 'cc_list') if len(object_.REQUEST.get('to_list', [])): comment = object_.REQUEST.get('comment', '').replace('<', '<').replace('>', '>') comment = safe_unicode(comment) notify(NotificationEvent(object_, comment)) object_.REQUEST.RESPONSE.redirect( object_.absolute_url() + (use_view_action and '/view' or '')) else: IStatusMessage(object_.REQUEST).addStatusMessage( _(u'statusmessage_no_recipients', default=u"You have to select at least one recipient"), type='error') object_.REQUEST.RESPONSE.redirect( object_.absolute_url() + '/notification_form')
def notification_sent(event): obj = event.obj comment = event.comment notifier = queryUtility(INotifier, name='email-notifier') if notifier is None: return if event.action is None: action = _(u"label_send_notification", default=u"Send Notification") else: action = event.action if event.actor is None: portal_state = getMultiAdapter((obj, obj.REQUEST), name=u'plone_portal_state') actor = portal_state.member().getId() else: actor = event.actor if event.time is None: time = DateTime() else: time = event.time to_list = obj.REQUEST.get('to_list', []) cc_list = obj.REQUEST.get('cc_list', []) readable_to = get_emails_from_ids(to_list) readable_cc = get_emails_from_ids(cc_list) journal_comment = translate( msgid=u'journal_notification_text', domain='ftw.notification.email', context=obj.REQUEST, mapping=dict( to_list=len(to_list) > 0 and ', '.join(readable_to) + '\n' or '-', cc_list=len(cc_list) > 0 and ', '.join(readable_cc) + '\n' or '-', comment=comment)) notify(JournalEntryEvent(obj, journal_comment, action)) notify(NotificationEmailSentEvent(obj, comment=comment, to_userids=to_list, cc_userids=cc_list)) kwargs = dict(action=action, actor=actor, time=time) notifier.send_notification( to_list=to_list, cc_list=cc_list, message=comment, object_=obj, **kwargs)
def columns_group(self): return ( {'column': 'to', 'column_title': '<input type="checkbox" id="all-group-to"/>' '<label for="all-group-to"> %s</label>' % ( translate(u'label_to', default='TO', domain="ftw.notification.base", context=self.request)), 'transform': checkbox_to_group_helper}, {'column': 'cc', 'column_title': '<input type="checkbox" id="all-group-cc"/>' '<label for="all-group-cc"> %s</label>' % ( translate(u'label_cc', default='CC', domain="ftw.notification.base", context=self.request)), 'transform': checkbox_cc_group_helper}, {'column': 'name', 'column_title': _(u'label_name', default='Name'), 'transform': groupname_helper})