示例#1
0
def subscribeable_channel_vocabulary(context):
    terms = []
    for channel in channel_lookup(only_subscribeable=True):
        terms.append(
            zope.schema.vocabulary.SimpleTerm(value=channel,
                                              token=channel.name,
                                              title=channel.title))
    return zope.schema.vocabulary.SimpleVocabulary(terms)
示例#2
0
def channel_vocabulary(context):
    terms = []
    for channel in channel_lookup():
        terms.append(
            zope.schema.vocabulary.SimpleTerm(value=channel,
                                              token=channel.name,
                                              title=channel.title))
    return zope.schema.vocabulary.SimpleVocabulary(terms)
示例#3
0
        def handleApply(self, action):
            data, errors = self.extractData()

            if not data.get(self.channel_selector):
                return

            if errors:
                self.status = form.AddForm.formErrorsMessage
                return

            extract = lambda d, prefix: dict(
                [(key.split('.', 1)[-1], value) for (key, value) in d.items()
                 if key.startswith(prefix)])

            comp_data = extract(data, 'composer.')
            coll_data = extract(data, 'collector.')

            pdata, perrors = self.parentForm.extractData()
            comp_data.update(pdata)

            composer = self.context.composers[self.format]
            secret = collective.singing.subscribe.secret(
                self.context,
                composer,
                comp_data,
                self.request)
            secret_provided = self.secret
            if secret_provided and secret != secret_provided:
                self.status = self.status_error
                return

            # Check if subscribed to other channels
            if not secret_provided and not self.parentForm.confirmation_sent:
                existing = sum(
                    [len(channel.subscriptions.query(secret=secret)) \
                     for channel in channel_lookup(only_subscribeable=True)])
                if existing:
                    self.status = self.status_already_subscribed
                    return

            metadata = dict(
                format=self.format,
                date=datetime.datetime.now(),
                pending=not secret_provided)

            # We assume here that the language of the request is the
            # desired language of the subscription:
            pl = component.queryAdapter(
                self.request, zope.i18n.interfaces.IUserPreferredLanguages)
            if pl is not None:
                metadata['languages'] = pl.getPreferredLanguages()

            # By using another method here we allow subclasses to override
            # what really happens here:
            self.add_subscription(
                self.context, secret, comp_data, coll_data, metadata,
                secret_provided)
def channel_vocabulary(context):
    terms = []
    for channel in channel_lookup():
        terms.append(
            zope.schema.vocabulary.SimpleTerm(
                value=channel,
                token=channel.name,
                title=channel.title))
    return zope.schema.vocabulary.SimpleVocabulary(terms)
def subscribeable_channel_vocabulary(context):
    terms = []
    for channel in channel_lookup(only_subscribeable=True):
        terms.append(
            zope.schema.vocabulary.SimpleTerm(
                value=channel,
                token=channel.name,
                title=channel.title))
    return zope.schema.vocabulary.SimpleVocabulary(terms)
示例#6
0
    def update(self):
        super(PrettySubscriptionsForm, self).update()

        # Let's set convert any 'pending' subscriptions to non-pending:
        for sub in self.subs:
            if sub.metadata.get('pending'):
                sub.metadata['pending'] = False

        # Assemble the list of edit forms
        self.subscription_editforms = [
            SubscriptionEditSubForm(s, self.request, self) for s in self.subs]

        # Assemble the list of add forms
        self.subscription_addforms = []
        for format, channel in self.channels:
            addform = SubscriptionAddSubForm(channel, self.request, self)
            addform.format = format
            self.subscription_addforms.append(addform)

        # The edit forms might have deleted a subscription.  We'll
        # take care of this while updating them:
        for form in self.subscription_editforms:
            form.update()
            if form.removed:
                subscription = form.context
                addform = SubscriptionAddSubForm(
                    subscription.channel, self.request, self)
                addform.format = subscription.metadata['format']
                addform.ignoreRequest = True
                addform.update()
                self.subscription_addforms.append(addform)
                addform.status = form.status
            #elif form.status != form.noChangesMessage:
            #    self.status = form.status

        # Let's update the add forms now.  One of them may have added
        # a subscription:
        for form in self.subscription_addforms:
            form.update()
            subscription = form.added
            if subscription is not None:
                editform = SubscriptionEditSubForm(
                    subscription, self.request, self)
                editform.update()
                self.subscription_editforms.append(editform)
                #_(u"You subscribed successfully.")
                editform.status = form.status

        # check if all subscriptions are now cancelled
        if not sum([len(c.subscriptions.query(secret=self.secret)) \
                for c in channel_lookup(only_subscribeable=True)]):
            self.unsubscribed_all = True
            self.status_message = _(u"You were unsubscribed completely.")
            # update after setting unsubscribed_all
            self.updateWidgets()
            del self.request.form['secret']
示例#7
0
        def handleApply(self, action):
            data, errors = self.extractData()

            if not data.get(self.channel_selector):
                return

            if errors:
                self.status = form.AddForm.formErrorsMessage
                return

            extract = lambda d, prefix: dict([(key.split('.', 1)[-1], value)
                                              for (key, value) in d.items()
                                              if key.startswith(prefix)])

            comp_data = extract(data, 'composer.')
            coll_data = extract(data, 'collector.')

            pdata, perrors = self.parentForm.extractData()
            comp_data.update(pdata)

            composer = self.context.composers[self.format]
            secret = collective.singing.subscribe.secret(
                self.context, composer, comp_data, self.request)
            secret_provided = self.secret
            if secret_provided and secret != secret_provided:
                self.status = self.status_error
                return

            # Check if subscribed to other channels
            if not secret_provided and not self.parentForm.confirmation_sent:
                existing = sum(
                    [len(channel.subscriptions.query(secret=secret)) \
                     for channel in channel_lookup(only_subscribeable=True)])
                if existing:
                    self.status = self.status_already_subscribed
                    return

            metadata = dict(format=self.format,
                            date=datetime.datetime.now(),
                            pending=not secret_provided)

            # We assume here that the language of the request is the
            # desired language of the subscription:
            pl = component.queryAdapter(
                self.request, zope.i18n.interfaces.IUserPreferredLanguages)
            if pl is not None:
                metadata['languages'] = pl.getPreferredLanguages()

            # By using another method here we allow subclasses to override
            # what really happens here:
            self.add_subscription(self.context, secret, comp_data, coll_data,
                                  metadata, secret_provided)
示例#8
0
 def __init__(self, context, request, subs, channels):
     super(PrettySubscriptionsForm, self).__init__(context, request)
     self.subs = subs
     self.channels = channels
     self.key_fields = []
     channels = channel_lookup(only_subscribeable=True)
     if channels:
         composers = reduce(lambda x, y: x + y,
                            [c.composers.values() for c in channels])
         for composer in composers:
             for name in composer.schema.names():
                 f = composer.schema.get(name)
                 if f and ISubscriptionKey.providedBy(f):
                     if f not in self.key_fields:
                         self.key_fields.append(f)
     self.confirmation_sent = False
示例#9
0
 def __init__(self, context, request, subs, channels):
     super(PrettySubscriptionsForm, self).__init__(context, request)
     self.subs = subs
     self.channels = channels
     self.key_fields = []
     channels = channel_lookup(only_subscribeable=True)
     if channels:
         composers = reduce(
             lambda x, y: x + y,
             [c.composers.values() for c in channels])
         for composer in composers:
             for name in composer.schema.names():
                 f = composer.schema.get(name)
                 if f and ISubscriptionKey.providedBy(f):
                     if f not in self.key_fields:
                         self.key_fields.append(f)
     self.confirmation_sent = False
示例#10
0
    def _subscriptions_and_channels(self, secret):
        subscriptions = []
        channels_and_formats = []

        for channel in channel_lookup(only_subscribeable=True):
            channel_subs = channel.subscriptions

            subscribed_formats = []
            if self.secret is not None:
                for s in channel_subs.query(secret=self.secret):
                    subscriptions.append(s)
                    subscribed_formats.append(s.metadata['format'])

            for format in channel.composers.keys():
                if format not in subscribed_formats:
                    channels_and_formats.append((format, channel))

        return subscriptions, channels_and_formats
示例#11
0
    def _subscriptions_and_channels(self, secret):
        subscriptions = []
        channels_and_formats = []

        for channel in channel_lookup(only_subscribeable=True):
            channel_subs = channel.subscriptions

            subscribed_formats = []
            if self.secret is not None:
                for s in channel_subs.query(secret=self.secret):
                    subscriptions.append(s)
                    subscribed_formats.append(s.metadata['format'])

            for format in channel.composers.keys():
                if format not in subscribed_formats:
                    channels_and_formats.append((format, channel))

        return subscriptions, channels_and_formats
示例#12
0
    def __call__(self):
        secret = self.request.form['secret']

        if secret:
            for channel in channel_lookup(only_subscribeable=True):
                subscriptions = channel.subscriptions.query(secret=secret)
                if len(subscriptions):
                    for sub in subscriptions:
                        if sub.metadata.get('pending', False):
                            sub.metadata['pending'] = False
                    self.status = self.successMessage
                    break
            else:
                self.status = self.notKnownMessage
        else:
            self.status = _(u"Can't identify your subscription. "
                            u"Please check your URL.")

        return self.template()
def ChannelAndCollectorVocab(context):
    terms = []
    for channel in channel_lookup(only_sendable=True):
        # use path so we can store the value savely if needed
        path = '/'.join(channel.getPhysicalPath())
        terms.append(zope.schema.vocabulary.SimpleTerm(
            value=(path, None),
            token=channel.name,
            title=channel.title))
        if channel.collector is not None:
            for collector in channel.collector.get_optional_collectors():
                # the value needs to be collector.title as
                # that is what is stored in the subscription
                terms.append(zope.schema.vocabulary.SimpleTerm(
                    value=(path, collector.title),
                    token=channel.name + "/" + collector.title,
                    title=channel.title + " - " + collector.title
                ))

    return SimpleVocabulary(terms)
示例#14
0
def ChannelAndCollectorVocab(context):
    terms = []
    for channel in channel_lookup(only_sendable=True):
        # use path so we can store the value savely if needed
        path = '/'.join(channel.getPhysicalPath())
        terms.append(
            zope.schema.vocabulary.SimpleTerm(value=(path, None),
                                              token=channel.name,
                                              title=channel.title))
        if channel.collector is not None:
            for collector in channel.collector.get_optional_collectors():
                # the value needs to be collector.title as
                # that is what is stored in the subscription
                terms.append(
                    zope.schema.vocabulary.SimpleTerm(
                        value=(path, collector.title),
                        token=channel.name + "/" + collector.title,
                        title=channel.title + " - " + collector.title))

    return SimpleVocabulary(terms)
示例#15
0
    def __call__(self):
        secret = self.request.form['secret']

        if secret:
            for channel in channel_lookup(only_subscribeable=True):
                subscriptions = channel.subscriptions.query(secret=secret)
                if len(subscriptions):
                    for sub in subscriptions:
                        if sub.metadata.get('pending', False):
                            sub.metadata['pending'] = False
                            notify_subscription_confirmed(sub)
                    self.status = self.successMessage
                    break
            else:
                self.status = self.notKnownMessage
        else:
            self.status = _(u"Can't identify your subscription. "
                            u"Please check your URL.")

        return self.template()
示例#16
0
    def _tick_and_dispatch(self):
        msg = u''

        queue = utils.get_queue()
        num = queue.process()
        if num:
            for job in queue.finished[-num:]:
                msg += job.value + '\n'

        for channel in channel_lookup():
            queued = status = None
            if channel.scheduler is not None:
                queued = channel.scheduler.tick(channel, self.request)
            if channel.queue is not None:
                status = channel.queue.dispatch()
            d = {'channel':channel.name,
                 'queued':queued or 0,
                 'status':str(status or (0,0))}
            msg += u'%(channel)s: %(queued)d messages queued, dispatched: %(status)s\n' % d
        return msg
示例#17
0
 def handle_bounce(self):
     """ """
     count = 0
     addrs = self.request['addrs']
     if isinstance(addrs, (str, unicode)):
         addrs = [addrs]
     for channel in channel_lookup(only_subscribeable=True):
         for addr in addrs:
             subscriptions = channel.subscriptions.query(key=addr)
             for sub in subscriptions:
                 md = sub.metadata
                 bounces = md.get('bounces', 0)
                 if bounces >= self.bounce_limit:
                     md['pending'] = True
                     bounces = 0
                     count += 1
                 else:
                     bounces += 1
                 md['bounces'] = bounces
     return "%d addresses received, %d deactivated" % (len(addrs), count)
示例#18
0
 def handle_bounce(self):
     """Process a list of bouncing e-mail addresses."""
     count = 0
     addrs = self.request['addrs']
     if isinstance(addrs, (str, unicode)):
         addrs = [addrs]
     for channel in channel_lookup(only_subscribeable=True):
         for addr in addrs:
             subscriptions = channel.subscriptions.query(key=addr)
             for sub in subscriptions:
                 md = sub.metadata
                 bounces = md.get('bounces', 0)
                 if bounces >= self.bounce_limit:
                     md['pending'] = True
                     bounces = 0
                     count += 1
                 else:
                     bounces += 1
                 md['bounces'] = bounces
     return "%d addresses received, %d deactivated" % (len(addrs), count)
示例#19
0
    def handle_send(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = form.EditForm.formErrorsMessage
            return

        address = data['address'].lower()
        for channel in channel_lookup():
            subscriptions = channel.subscriptions.query(key=address)
            if len(subscriptions):
                subscription = tuple(subscriptions)[0]
                composer = channel.composers[subscription.metadata['format']]
                msg = composer.render_forgot_secret(subscription)
                status, status_msg = message.dispatch(msg)
                if status != u'sent':
                    raise RuntimeError(
                        "There was an error with sending your e-mail.  Please "
                        "try again later.")
                self.status = self.successMessage
                break
        else:
            self.status = self.notKnownMessage
示例#20
0
    def _tick_and_dispatch(self):
        msg = u''

        queue = utils.get_queue()
        num = queue.process()
        if num:
            for job in queue.finished[-num:]:
                msg += job.value + '\n'

        for channel in channel_lookup():
            queued = status = None
            if channel.scheduler is not None:
                queued = channel.scheduler.tick(channel, self.request)
            if channel.queue is not None:
                status = channel.queue.dispatch()
            d = {
                'channel': channel.name,
                'queued': queued or 0,
                'status': str(status or (0, 0))
            }
            msg += u'%(channel)s: %(queued)d messages queued, dispatched: %(status)s\n' % d
        return msg
示例#21
0
    def update(self):
        super(PrettySubscriptionsForm, self).update()

        # Let's set convert any 'pending' subscriptions to non-pending:
        for sub in self.subs:
            if sub.metadata.get('pending'):
                sub.metadata['pending'] = False

        # Assemble the list of edit forms
        self.subscription_editforms = [
            SubscriptionEditSubForm(s, self.request, self) for s in self.subs
        ]

        # Assemble the list of add forms
        self.subscription_addforms = []
        for format, channel in self.channels:
            addform = SubscriptionAddSubForm(channel, self.request, self)
            addform.format = format
            self.subscription_addforms.append(addform)

        # The edit forms might have deleted a subscription.  We'll
        # take care of this while updating them:
        for form in self.subscription_editforms:
            form.update()
            if form.removed:
                subscription = form.context
                addform = SubscriptionAddSubForm(subscription.channel,
                                                 self.request, self)
                addform.format = subscription.metadata['format']
                addform.ignoreRequest = True
                addform.update()
                self.subscription_addforms.append(addform)
                addform.status = form.status
            #elif form.status != form.noChangesMessage:
            #    self.status = form.status

        # The edit forms might have deleted a subscription.  We'll
        # take care of this while updating them:
        for form in self.subscription_editforms:
            form.update()
            if form.removed:
                subscription = form.context
                addform = SubscriptionAddSubForm(subscription.channel,
                                                 self.request, self)
                addform.format = subscription.metadata['format']
                addform.ignoreRequest = True
                addform.update()
                self.subscription_addforms.append(addform)
                addform.status = form.status
            #elif form.status != form.noChangesMessage:
            #    self.status = form.status

        # Let's update the add forms now.  One of them may have added
        # a subscription:
        for form in self.subscription_addforms:
            form.update()
            subscription = form.added
            if subscription is not None:
                editform = SubscriptionEditSubForm(subscription, self.request,
                                                   self)
                editform.update()
                self.subscription_editforms.append(editform)
                #_(u"You subscribed successfully.")
                editform.status = form.status

        # check if all subscriptions are now cancelled
        if not sum([len(c.subscriptions.query(secret=self.secret)) \
                for c in channel_lookup(only_subscribeable=True)]):
            self.unsubscribed_all = True
            self.status_message = _(u"You were unsubscribed completely.")
            # update after setting unsubscribed_all
            self.updateWidgets()
            del self.request.form['secret']
示例#22
0
    def update(self):
        super(PrettySubscriptionsForm, self).update()
        # Let's set convert any 'pending' subscriptions to non-pending:
        for sub in self.subs:
            if sub.metadata.get('pending'):
                sub.metadata['pending'] = False

        # Assemble the list of edit forms
        self.subscription_editforms = [
            SubscriptionEditSubForm(s, self.request, self) for s in self.subs]

        # Assemble the list of add forms
        self.subscription_addforms = []
        for format, channel in self.channels:
            addform = SubscriptionAddSubForm(channel, self.request, self)
            addform.format = format
            self.subscription_addforms.append(addform)

        # The edit forms might have deleted a subscription.  We'll
        # take care of this while updating them:
        list_remove_channel = []
        for form in self.subscription_editforms:
            form.update()
            if form.removed:
                try:
                    list_remove_channel.append(form.context.channel.title)
                except:
                    pass
                subscription = form.context
                addform = SubscriptionAddSubForm(
                    subscription.channel, self.request, self)
                addform.format = subscription.metadata['format']
                addform.ignoreRequest = True
                addform.update()
                self.subscription_addforms.append(addform)
                addform.status = form.status
            #elif form.status != form.noChangesMessage:
            #    self.status = form.status

        # The edit forms might have deleted a subscription.  We'll
        # take care of this while updating them:
        for form in self.subscription_editforms:
            form.update()
            if form.removed:
                subscription = form.context
                addform = SubscriptionAddSubForm(
                    subscription.channel, self.request, self)
                addform.format = subscription.metadata['format']
                addform.ignoreRequest = True
                addform.update()
                self.subscription_addforms.append(addform)
                addform.status = form.status
            #elif form.status != form.noChangesMessage:
            #    self.status = form.status

        # Let's update the add forms now.  One of them may have added
        # a subscription:
        list_add_channel = []
        for form in self.subscription_addforms:
            form.update()
            subscription = form.added
            if subscription is not None:
                try:
                    list_add_channel.append(form.context.title)
                except:
                    pass
                editform = SubscriptionEditSubForm(
                    subscription, self.request, self)
                editform.update()
                self.subscription_editforms.append(editform)
                #_(u"You subscribed successfully.")
                editform.status = form.status

        if list_remove_channel or list_add_channel or self.unsubscribed_all:
            mhost = getToolByName(self.context, 'MailHost')
            email_user = self.request.form.get('form.widgets.email')
            selected = self.getSelected(self.forms)
            messageText = 'O usuario ' + email_user + ' alterou as seguintes configuracoes: \n'
            if list_remove_channel:
                remove_channel = ''
                for i in list_remove_channel:
                    remove_channel += i
                    if i != list_remove_channel[-1]:
                        remove_channel += ', '
                messageText += 'Removeu os canais: ' + remove_channel + '. \n'
            if list_add_channel:
                add_channel = ''
                for i in list_add_channel:
                    add_channel += i
                    if i != list_add_channel[-1]:
                        add_channel += ', '
                messageText += 'Adicionou os canais: ' + add_channel + '. \n'
            if selected:
                selected_channel = ''
                for i in selected:
                    selected_channel += i
                    if i != selected[-1]:
                        selected_channel += ', '
                messageText += 'Configuracao atual: ' + selected_channel + '. \n'
                
            #variaveis que definem os emails de envio para o admin
            #Verificar se existe a propriedade em portal_newsletters -->  report_to
            mto = self.context.getProperty('report_to')
            mfrom = self.context.aq_parent.getProperty('email_from_address')
            subject = 'Alteração de configuração pessoais no clipping'
            mhost.send(messageText, mto, mfrom, subject)

        # check if all subscriptions are now cancelled
        if not sum([len(c.subscriptions.query(secret=self.secret)) \
                for c in channel_lookup(only_subscribeable=True)]):
            self.unsubscribed_all = True
            self.status_message = _(u"You were unsubscribed completely.")
            # update after setting unsubscribed_all
            self.updateWidgets()
            try:
                del self.request.form['secret']
            except:
                pass
示例#23
0
 def get_items(self):
     return [(channel.name, ChannelStatistics(channel))
             for channel in channel_lookup()]
示例#24
0
 def all_channels(self):
     return channel_lookup(only_subscribeable=True)
示例#25
0
 def get_items(self):
     return [(channel.name, ChannelStatistics(channel))
             for channel in channel_lookup()]