コード例 #1
0
class ContentruleSubscriptionForm(form.Form):
    fields = field.Fields(IContentruleSubscription)
    fields['rules'].widgetFactory = CheckBoxFieldWidget
    fields['norobots'].widgetFactory = NorobotsFieldWidget
    ignoreContext = True  # don't use context to get widget data
    label = _("Subscribe to site notifications")
    description = _(
        "In this form you can choose which notifications subscribe for.")

    def updateWidgets(self):
        super(ContentruleSubscriptionForm, self).updateWidgets()
        pm = getToolByName(self.context, 'portal_membership')
        user_email = pm.getAuthenticatedMember().getProperty('email')
        if user_email:
            self.widgets["email"].value = user_email

    @button.buttonAndHandler(_(u'Subscribe'))
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            return
        rules_tool = getToolByName(self.context,
                                   'contentrules_subscription_tool')
        errors = []
        for rule in data.get('rules'):
            result, msg = rules_tool.registerUser(rule, data.get('email', ''))
            if not result:
                IStatusMessage(self.request).addStatusMessage(msg, "error")
            else:
                IStatusMessage(self.request).addStatusMessage(
                    _(u"You are subscribed succesfully."), "info")
        self.context.REQUEST.RESPONSE.redirect("@@notify-subscribe")
コード例 #2
0
class IMailSubscriptionsAction(Interface):
    """Definition of the configuration available for a mail action
    """
    subject = schema.TextLine(title=_plone(u"Subject"),
                              description=_plone(u"Subject of the message"),
                              required=True)
    source = schema.TextLine(
        title=_plone(u"Email source"),
        description=_plone("The email address that sends the \
email. If no email is provided here, it will use the portal from address."),
        required=False)
    message = schema.Text(title=_(u"Message"),
                          description=_(u"The message that you want to mail."),
                          required=True)
コード例 #3
0
class IContentruleSubscription(interface.Interface):
    email = schema.TextLine(title=_(u"Email"),
                            constraint=isEmail,
                            required=True)

    rules = schema.Tuple(
        title=_(u'Available notifications'),
        description=
        _(u"These are the available notifications which you can subscribe for."
          ),
        value_type=schema.Choice(
            vocabulary=
            u"contentrules.subscription.vocabularies.SubscriptionRulesVocabulary"
        ),
        required=True,
        missing_value=())
    norobots = schema.TextLine(
        title=_(u'Are you a human ?'),
        description=_(
            u'In order to avoid spam, please answer the question below.'),
        required=True)
コード例 #4
0
class MailSubscriptionsEditForm(EditForm):
    """
    An edit form for the mail action
    """
    form_fields = form.FormFields(IMailSubscriptionsAction)
    label = _plone(u"Edit Mail Subscriptions Action")
    description = _(
        u'form_description',
        default=u"A mail action that can mail users subscribed to this rule")
    form_name = _plone(u"Configure element")

    # custom template will allow us to add help text
    template = ViewPageTemplateFile('templates/mail.pt')
 def handleApply(self, action):
     data, errors = self.extractData()
     if errors:
         return
     rules_tool = getToolByName(self.context, 'contentrules_subscription_tool')
     errors = []
     for rule in data.get('rules'):
         result, msg = rules_tool.registerUser(rule, data.get('email', ''))
         if not result:
             IStatusMessage(self.request).addStatusMessage(msg, "error")
         else:
             IStatusMessage(self.request).addStatusMessage(_(u"You are subscribed succesfully."),
                                                   "info")
     self.context.REQUEST.RESPONSE.redirect("@@notify-subscribe")
コード例 #6
0
 def handleApply(self, action):
     data, errors = self.extractData()
     if errors:
         return
     rules_tool = getToolByName(self.context,
                                'contentrules_subscription_tool')
     errors = []
     for rule in data.get('rules'):
         result, msg = rules_tool.registerUser(rule, data.get('email', ''))
         if not result:
             IStatusMessage(self.request).addStatusMessage(msg, "error")
         else:
             IStatusMessage(self.request).addStatusMessage(
                 _(u"You are subscribed succesfully."), "info")
     self.context.REQUEST.RESPONSE.redirect("@@notify-subscribe")
コード例 #7
0
 def updateSubscriptions(self):
     """
     Update subscriptions in the tool with the values in the request
     """
     subscriptions = self.getSubscriptions()
     for key in subscriptions.keys():
         if key in self.request.form:
             new_values = self.request.form.get(key, [])
             if new_values:
                 subscriptions[key] = new_values
         else:
             del subscriptions[key]
     IStatusMessage(self.request).addStatusMessage(_(u"Subscriptions updated"), "info")
     root = self.context.portal_url()
     self.request.RESPONSE.redirect('%s/@@contentrules-subscription-controlpanel' % root)
コード例 #8
0
class MailSubscriptionsAddForm(AddForm):
    """
    An add form for the mail action
    """
    form_fields = form.FormFields(IMailSubscriptionsAction)
    label = _plone(u"Add Mail Action")
    description = _(
        u'form_description',
        default=u"A mail action that can mail users subscribed to this rule")
    form_name = _plone(u"Configure element")

    # custom template will allow us to add help text
    template = ViewPageTemplateFile('templates/mail.pt')

    def create(self, data):
        a = MailSubscriptionsAction()
        form.applyChanges(a, self.form_fields, data)
        return a
コード例 #9
0
 def registerUser(self, rule_id, email):
     """
     Insert the given email address in the given rule_id
     """
     if not rule_id in self.subscriptions:
         self.subscriptions[rule_id] = [email]
     else:
         if email in self.subscriptions[rule_id]:
             factory = getUtility(IVocabularyFactory,
                                  "contentrules.subscription.vocabularies.SubscriptionRulesVocabulary")
             vocabulary = factory(self)
             rule_term = vocabulary.getTerm(rule_id)
             msg = _('already_subscribed_error',
                     default='The given email is already present for "${title}"',
                     mapping=dict(title=rule_term.title))
             return False, msg
         else:
             self.subscriptions[rule_id].append(email)
     return True, ""
コード例 #10
0
 def summary(self):
     return _(u"Email report to users subscribed")
コード例 #11
0
class IsEmailError(schema.ValidationError):
    __doc__ = _("""You entered an invalid email address.""")
コード例 #12
0
 def summary(self):
     return _(u"Email report to users subscribed")