コード例 #1
0
    def update(self):
        self.notification = RegistrationNotification(getSite())

        super(NotificationsForm, self).update()

        request = self.request

        if 'form.unsubscribe' in request:
            principals = request.get('form.principals', ())
            for pid in principals:
                self.notification.unsubscribe(pid)

            if principals:
                IStatusMessage(request).add(
                    _('Selected users have been unsubscribed.'))

        principals = []
        auth = getUtility(IAuthentication)

        for pid in self.notification.getSubscribers(getSite()):
            try:
                principal = auth.getPrincipal(pid)
            except PrincipalLookupError:
                continue

            profile = IPersonalProfile(principal)
            principals.append(
                (profile.title, {'id': pid, 'title': profile.title}))

        principals.sort()
        self.principals = [info for _t, info in principals]
コード例 #2
0
class NotificationsForm(WizardStepForm):

    fields = Fields(INotificationsForm)
    ignoreContext = True

    def update(self):
        self.notification = RegistrationNotification(getSite())

        super(NotificationsForm, self).update()

        request = self.request

        if 'form.unsubscribe' in request:
            principals = request.get('form.principals', ())
            for pid in principals:
                self.notification.unsubscribe(pid)

            if principals:
                IStatusMessage(request).add(
                    _('Selected users have been unsubscribed.'))

        principals = []
        auth = getUtility(IAuthentication)

        for pid in self.notification.getSubscribers(getSite()):
            try:
                principal = auth.getPrincipal(pid)
            except PrincipalLookupError:
                continue

            profile = IPersonalProfile(principal)
            principals.append(
                (profile.title, {'id': pid, 'title': profile.title}))

        principals.sort()
        self.principals = [info for _t, info in principals]

    @button.buttonAndHandler(_(u'Select'), name="select", provides=ISaveAction)
    def selectButtonHandler(self, action):
        data, errors = self.extractData()
        if not data['principal']:
            IStatusMessage(self.request).add(
                _('Please select user.'), 'warning')
        else:
            self.notification.subscribe(data['principal'])
            IStatusMessage(self.request).add(_('User has been subscribed.'))
            self.redirect('.')