Exemple #1
0
 def _add_rule(self, arg, req):
     rule = Subscription(self.env)
     rule['sid'] = req.session.sid
     rule['authenticated'] = req.session.authenticated and 1 or 0
     rule['distributor'] = arg
     rule['format'] = req.args.get('format-%s' % arg, '')
     rule['adverb'] = req.args['new-adverb-%s' % arg]
     rule['class'] = req.args['new-rule-%s' % arg]
     Subscription.add(self.env, rule)
Exemple #2
0
 def _add_rule(self, arg, req):
     rule = Subscription(self.env)
     rule['sid'] = req.session.sid
     rule['authenticated'] = req.session.authenticated and 1 or 0
     rule['distributor'] = arg
     rule['format'] = req.args.get('format-%s'%arg, '')
     rule['adverb'] = req.args['new-adverb-%s'%arg]
     rule['class'] = req.args['new-rule-%s'%arg]
     Subscription.add(self.env, rule)
Exemple #3
0
 def test_init(self):
     # Examine properties of the initialized object.
     fields = ('id', 'sid', 'authenticated', 'distributor', 'format',
               'priority', 'adverb', 'class')
     sub = Subscription(self.env)
     for field in fields:
         self.assertEqual(sub[field], None)
     # Check basic class method for subscription presentation too.
     sub = self.sub
     self.assertEqual(sub.subscription_tuple(),
                      (sub['class'], sub['distributor'], sub['sid'],
                       sub['authenticated'], None, sub['format'],
                       sub['priority'], sub['adverb']))
Exemple #4
0
 def test_init(self):
     # Examine properties of the initialized objekt.
     fields = ('id', 'sid', 'authenticated', 'distributor', 'format',
               'priority', 'adverb', 'class')
     sub = Subscription(self.env)
     for field in fields:
         self.assertEqual(sub[field], None)
     # Check basic class method for subscription presentation too.
     sub = self.sub
     self.assertEqual(sub.subscription_tuple(),
                          (sub['class'], sub['distributor'], sub['sid'],
                           sub['authenticated'], None, sub['format'],
                           sub['priority'], sub['adverb']))
    def matches(self, event):
        if event.realm != 'ticket':
            return
        if event.category not in ('created', 'changed', 'attachment added'):
            return

        klass = self.__class__.__name__
        cc = event.target['cc'] or ''
        sids = set()
        for chunk in re.split('\s|,', cc):
            chunk = chunk.strip()

            if not chunk or chunk.startswith('@'):
                continue

            if re.match(r'^[^@]+@.+', chunk):
                sid, auth, addr = None, 0, chunk
            else:
                sid, auth, addr = chunk, 1, None

            # Default subscription
            for s in self.default_subscriptions():
                yield (s[0], s[1], sid, auth, addr, None, s[2], s[3])
            if sid:
                sids.add((sid, auth))

        for s in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield s.subscription_tuple()
Exemple #6
0
    def matches(self, event):
        if event.realm != 'wiki':
            return
        if event.category not in ('changed', 'created', 'attachment added',
                                  'deleted', 'version deleted'):
            return

        klass = self.__class__.__name__

        attrs = SubscriptionAttribute.find_by_class_and_realm(
            self.env, klass, 'wiki')

        def match(pattern):
            for raw in pattern['target'].split(' '):
                if raw != '':
                    pat = urllib.unquote(raw).replace('*', '.*')
                    if re.match(pat, event.target.name):
                        return True

        sids = set(
            map(lambda x: (x['sid'], x['authenticated']), filter(match,
                                                                 attrs)))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #7
0
    def matches(self, event):
        if event.realm != "ticket":
            return
        if event.category not in ('created', 'changed', 'attachment added'):
            return

        ticket = event.target
        if not ticket['reporter'] or ticket['reporter'] == 'anonymous':
            return

        if re.match(r'^[^@]+@.+', ticket['reporter']):
            sid, auth, addr = None, 0, ticket['reporter']
        else:
            sid, auth, addr = ticket['reporter'], 1, None

        # Default subscription
        for s in self.default_subscriptions():
            yield (s[0], s[1], sid, auth, addr, None,
                    s[2], s[3])

        if sid:
            klass = self.__class__.__name__
            for s in Subscription.find_by_sids_and_class(self.env,
                    ((sid,auth),), klass):
                yield s.subscription_tuple()
Exemple #8
0
    def matches(self, event):
        if event.realm != "ticket":
            return
        if event.category not in ("changed", "created", "attachment added"):
            return

        klass = self.__class__.__name__
        ticket = event.target
        sids = set()

        for field in self.custom_cc_fields:
            subs = ticket[field] or ""
            for chunk in re.split("\s|,", subs):
                chunk = chunk.strip()
                if not chunk or chunk.startswith("@"):
                    continue

                if re.match(r"^[^@]+@.+", chunk):
                    sid, auth, addr = None, None, chunk
                else:
                    sid, auth, addr = chunk, True, None

                # Default subscription
                for s in self.default_subscriptions():
                    yield (s[0], s[1], sid, auth, addr, None, s[3], s[4])
                if sid:
                    sids.add((sid, auth))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #9
0
    def matches(self, event):
        if event.realm != 'ticket':
            return
        if event.category not in ('changed', 'created', 'attachment added'):
            return

        klass = self.__class__.__name__
        ticket = event.target
        sids = set()

        for field in self.custom_cc_fields:
            subs = ticket[field] or ''
            for chunk in re.split('\s|,', subs):
                chunk = chunk.strip()
                if not chunk or chunk.startswith('@'):
                    continue

                if re.match(r'^[^@]+@.+', chunk):
                    sid, auth, addr = None, None, chunk
                else:
                    sid, auth, addr = chunk, True, None

                # Default subscription
                for s in self.default_subscriptions():
                    yield (s[0], s[1], sid, auth, addr, None, s[3], s[4])
                if sid:
                    sids.add((sid, auth))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
    def matches(self, event):
        if event.realm != 'ticket':
            return
        if event.category not in ('created', 'changed', 'attachment added'):
            return
        ticket = event.target

        try:
            component = model.Component(self.env, ticket['component'])
            if not component.owner:
                return

            if re.match(r'^[^@]+@.+', component.owner):
                sid, auth, addr = None, 0, component.owner
            else:
                sid, auth, addr = component.owner, 1, None

            # Default subscription
            for s in self.default_subscriptions():
                yield s[0], s[1], sid, auth, addr, None, s[2], s[3]

            if sid:
                klass = self.__class__.__name__
                for s in Subscription.find_by_sids_and_class(self.env,
                                                             ((sid, auth),),
                                                             klass):
                    yield s.subscription_tuple()

        except:
            self.log.debug("Component for ticket (%s) not found",
                           ticket['id'])
Exemple #11
0
    def matches(self, event):
        if event.realm != "ticket":
            return
        if event.category not in ('created', 'changed', 'attachment added'):
            return
        ticket = event.target

        try:
            component = model.Component(self.env, ticket['component'])
            if not component.owner:
                return

            if re.match(r'^[^@]+@.+', component.owner):
                sid, auth, addr = None, 0, component.owner
            else:
                sid, auth, addr = component.owner, 1, None

            # Default subscription
            for s in self.default_subscriptions():
                yield (s[0], s[1], sid, auth, addr, None, s[2], s[3])

            if sid:
                klass = self.__class__.__name__
                for s in Subscription.find_by_sids_and_class(
                        self.env, ((sid, auth), ), klass):
                    yield s.subscription_tuple()

        except:
            self.log.debug("Component for ticket (%s) not found" %
                           ticket['id'])
Exemple #12
0
    def matches(self, event):
        klass = self.__class__.__name__

        attrs = SubscriptionAttribute.find_by_class_realm_and_target(self.env, klass, "user", event.author)
        sids = set(map(lambda x: (x["sid"], x["authenticated"]), attrs))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #13
0
    def matches(self, event):
        if event.realm != 'blog':
            return
        if event.category != 'post created':
            return

        klass = self.__class__.__name__
        for i in Subscription.find_by_class(self.env, klass):
            yield i.subscription_tuple()
Exemple #14
0
    def matches(self, event):
        if event.realm != 'blog':
            return
        if event.category != 'post created':
            return

        klass = self.__class__.__name__
        for i in Subscription.find_by_class(self.env, klass):
            yield i.subscription_tuple()
    def matches(self, event):
        if event.realm != 'ticket':
            return
        if event.category not in ('changed', 'created', 'attachment added'):
            return

        klass = self.__class__.__name__
        for i in Subscription.find_by_class(self.env, klass):
            yield i.subscription_tuple()
Exemple #16
0
    def matches(self, event):
        klass = self.__class__.__name__

        attrs = SubscriptionAttribute.find_by_class_realm_and_target(self.env,
                klass, event.realm, self._get_target_id(event.target))
        sids = set(map(lambda x: (x['sid'],x['authenticated']), attrs))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #17
0
    def matches(self, event):
        if event.realm != 'ticket':
            return
        if event.category not in ('changed', 'created', 'attachment added'):
            return

        klass = self.__class__.__name__
        for i in Subscription.find_by_class(self.env, klass):
            yield i.subscription_tuple()
Exemple #18
0
    def matches(self, event):
        klass = self.__class__.__name__

        attrs = SubscriptionAttribute.find_by_class_realm_and_target(
            self.env, klass, event.realm, get_target_id(event.target))
        sids = set(map(lambda x: (x['sid'], x['authenticated']), attrs))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #19
0
    def matches(self, event):
        if event.realm != 'acct_mgr':
            return
        # DEVEL: Need a better plan, because the real issue is a missing
        #   user_* method on AccountManager changes.
        if not event.category in self.categories:
            return

        klass = self.__class__.__name__
        for i in Subscription.find_by_class(self.env, klass):
            yield i.subscription_tuple()
Exemple #20
0
    def setUp(self):
        SubscriptionTestSetup.setUp(self)

        self.sub = Subscription(self.env)
        self.sub['sid'] = 'user'
        self.sub['authenticated'] = 1
        self.sub['distributor'] = 'email'
        self.sub['format'] = 'text/plain'
        self.sub['priority'] = 1
        self.sub['adverb'] = 'always'
        self.sub['class'] = 'GeneralWikiSubscriber'
    def matches(self, event):
        if event.realm != 'acct_mgr':
            return
        # DEVEL: Need a better plan, because the real issue is a missing
        #   user_* method on AccountManager changes.
        if event.category not in self.categories:
            return

        klass = self.__class__.__name__
        for i in Subscription.find_by_class(self.env, klass):
            yield i.subscription_tuple()
Exemple #22
0
    def matches(self, event):
        if event.realm != 'blog':
            return
        if not event.category in ('post created', 'post changed',
                                  'post deleted', 'comment created',
                                  'comment changed', 'comment deleted'):
            return

        klass = self.__class__.__name__
        for i in Subscription.find_by_class(self.env, klass):
            yield i.subscription_tuple()
    def matches(self, event):
        if event.realm != 'blog':
            return
        if event.category not in ('post created', 'post changed',
                                  'post deleted', 'comment created',
                                  'comment changed', 'comment deleted'):
            return

        klass = self.__class__.__name__
        for i in Subscription.find_by_class(self.env, klass):
            yield i.subscription_tuple()
Exemple #24
0
    def matches(self, event):
        if event.realm != "ticket":
            return
        if event.category not in ('created', 'changed', 'attachment added'):
            return
        ticket = event.target

        if (not ticket['owner'] or ticket['owner'] == 'anonymous') and \
                not 'owner' in event.changes:
            return

        sid = sid_old = None
        if ticket['owner'] and ticket['owner'] != 'anonymous':
            if re.match(r'^[^@]+@.+', ticket['owner']):
                sid, auth, addr = None, 0, ticket['owner']
            else:
                sid, auth, addr = ticket['owner'], 1, None
        if 'owner' in event.changes:
            previous_owner = event.changes['owner']
            if re.match(r'^[^@]+@.+', previous_owner):
                sid_old, auth_old, addr_old = None, 0, previous_owner
            else:
                sid_old, auth_old, addr_old = previous_owner, 1, None

        # Default subscription
        for s in self.default_subscriptions():
            if sid:
                yield (s[0], s[1], sid, auth, addr, None, s[2], s[3])
            if sid_old:
                yield (s[0], s[1], sid_old, auth_old, addr_old, None, s[2],
                       s[3])
        if sid:
            klass = self.__class__.__name__
            for s in Subscription.find_by_sids_and_class(self.env,
                    ((sid, auth),), klass):
                yield s.subscription_tuple()
        if sid_old:
            klass = self.__class__.__name__
            for s in Subscription.find_by_sids_and_class(self.env,
                    ((sid_old, auth_old),), klass):
                yield s.subscription_tuple()
    def matches(self, event):
        if event.realm != 'blog':
            return
        if event.category not in ('post changed', 'post deleted',
                                  'comment created', 'comment changed',
                                  'comment deleted'):
            return

        sids = ((event.blog_post.author, 1),)
        klass = self.__class__.__name__
        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #26
0
    def matches(self, event):
        if event.realm != 'blog':
            return
        if not event.category in ('post changed',
                                  'post deleted',
                                  'comment created',
                                  'comment changed',
                                  'comment deleted'):
            return

        sids = ((event.blog_post.author,1),)
        klass = self.__class__.__name__
        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #27
0
 def _get_preferred_format(self, realm, sid, authenticated):
     if authenticated is None:
         authenticated = 0
     # Format is unified for all subscriptions of a user.
     result = Subscription.find_by_sid_and_distributor(
         self.env, sid, authenticated, 'email')
     if result:
         chosen = result[0]['format']
         self.log.debug("EmailDistributor determined the preferred format"
                        " for '%s (%s)' is: %s", sid, authenticated and
                        'authenticated' or 'not authenticated', chosen)
         return chosen
     else:
         return self._get_default_format()
Exemple #28
0
 def _get_preferred_format(self, realm, sid, authenticated):
     if authenticated is None:
         authenticated = 0
     # Format is unified for all subscriptions of a user.
     result = Subscription.find_by_sid_and_distributor(
              self.env, sid, authenticated, 'email')
     if result:
         chosen = result[0]['format']
         self.log.debug("EmailDistributor determined the preferred format" \
                 " for '%s (%s)' is: %s"%(sid, authenticated and \
                 'authenticated' or 'not authenticated', chosen))
         return chosen
     else:
         return self._get_default_format()
    def matches(self, event):
        if event.realm != 'blog':
            return
        if event.category not in ('post created', 'post changed',
                                  'post deleted', 'comment created',
                                  'comment changed', 'comment deleted'):
            return

        klass = self.__class__.__name__

        sids = set(map(lambda x: (x['sid'], x['authenticated']),
                       SubscriptionAttribute.find_by_class_realm_and_target(
                           self.env, klass, 'blog', event.blog_post.author)))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #30
0
    def matches(self, event):
        if event.realm != 'blog':
            return
        if not event.category in ('post created', 'post changed',
                                  'post deleted', 'comment created',
                                  'comment changed', 'comment deleted'):
            return

        klass = self.__class__.__name__

        attrs = SubscriptionAttribute.find_by_class_realm_and_target(
            self.env, klass, 'blog', event.blog_post.name)
        sids = set(map(lambda x: (x['sid'], x['authenticated']), attrs))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #31
0
    def matches(self, event):
        if event.realm != "ticket":
            return
        if event.category not in ("changed", "created", "attachment added"):
            return

        component = event.target["component"]
        if not component:
            return

        klass = self.__class__.__name__

        attrs = SubscriptionAttribute.find_by_class_realm_and_target(self.env, klass, "ticket", component)
        sids = set(map(lambda x: (x["sid"], x["authenticated"]), attrs))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
    def matches(self, event):
        if event.realm != 'ticket':
            return
        if event.category not in ('changed', 'created', 'attachment added'):
            return

        component = event.target['component']
        if not component:
            return

        klass = self.__class__.__name__

        attrs = SubscriptionAttribute.find_by_class_realm_and_target(
            self.env, klass, 'ticket', component)
        sids = set(map(lambda x: (x['sid'], x['authenticated']), attrs))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #33
0
    def matches(self, event):
        if event.realm != 'ticket':
            return
        if event.category not in ('changed', 'created', 'attachment added'):
            return

        component = event.target['component']
        if not component:
            return

        klass = self.__class__.__name__

        attrs = SubscriptionAttribute.find_by_class_realm_and_target(
            self.env, klass, 'ticket', component)
        sids = set(map(lambda x: (x['sid'], x['authenticated']), attrs))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #34
0
    def matches(self, event):
        if event.realm != "wiki":
            return
        if event.category not in ("changed", "created", "attachment added", "deleted", "version deleted"):
            return

        klass = self.__class__.__name__

        attrs = SubscriptionAttribute.find_by_class_and_realm(self.env, klass, "wiki")

        def match(pattern):
            for raw in pattern["target"].split(" "):
                if raw != "":
                    pat = urllib.unquote(raw).replace("*", ".*")
                    if re.match(pat, event.target.name):
                        return True

        sids = set(map(lambda x: (x["sid"], x["authenticated"]), filter(match, attrs)))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #35
0
    def matches(self, event):
        if event.realm != "ticket":
            return
        if event.category not in ("changed", "created", "attachment added"):
            return

        klass = self.__class__.__name__
        ticket = event.target
        sids = set()

        cc = event.target["cc"] or ""
        for chunk in re.split("\s|,", cc):
            chunk = chunk.strip()
            if chunk and chunk.startswith("@"):
                member = None
                grp = chunk[1:]

                attrs = SubscriptionAttribute.find_by_class_realm_and_target(self.env, klass, "ticket", grp)
                sids.update(set(map(lambda x: (x["sid"], x["authenticated"]), attrs)))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #36
0
    def matches(self, event):
        if event.realm != "ticket":
            return
        if event.category not in ('created', 'changed', 'attachment added'):
            return
        if not event.author or event.author == 'anonymous':
            return

        if re.match(r'^[^@]+@.+', event.author):
            sid, auth, addr = None, 0, event.author
        else:
            sid, auth, addr = event.author, 1, None

        # Default subscription
        for s in self.default_subscriptions():
            yield (s[0], s[1], sid, auth, addr, None, s[2], s[3])

        if sid:
            klass = self.__class__.__name__
            for s in Subscription.find_by_sids_and_class(self.env,
                    ((sid,auth),), klass):
                yield s.subscription_tuple()
    def matches(self, event):
        if event.realm != 'ticket':
            return
        if event.category not in ('changed', 'created', 'attachment added'):
            return

        klass = self.__class__.__name__
        sids = set()

        cc = event.target['cc'] or ''
        for chunk in re.split('\s|,', cc):
            chunk = chunk.strip()
            if chunk and chunk.startswith('@'):
                grp = chunk[1:]

                attrs = SubscriptionAttribute.\
                    find_by_class_realm_and_target(self.env, klass,
                                                   'ticket', grp)
                sids.update(set(map(
                    lambda x: (x['sid'], x['authenticated']), attrs)))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
    def matches(self, event):
        if event.realm != 'ticket':
            return
        if event.category not in ('changed', 'created', 'attachment added'):
            return

        klass = self.__class__.__name__
        sids = set()

        cc = event.target['cc'] or ''
        for chunk in re.split('\s|,', cc):
            chunk = chunk.strip()
            if chunk and chunk.startswith('@'):
                grp = chunk[1:]

                attrs = SubscriptionAttribute.\
                    find_by_class_realm_and_target(self.env, klass,
                                                   'ticket', grp)
                sids.update(
                    set(map(lambda x: (x['sid'], x['authenticated']), attrs)))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #39
0
    def matches(self, event):
        if event.realm != 'wiki':
            return
        if event.category not in ('changed', 'created', 'attachment added',
                'deleted', 'version deleted'):
            return

        klass = self.__class__.__name__

        attrs = SubscriptionAttribute.find_by_class_and_realm(
                self.env, klass, 'wiki')

        def match(pattern):
            for raw in pattern['target'].split(' '):
                if raw != '':
                    pat = urllib.unquote(raw).replace('*', '.*')
                    if re.match(pat, event.target.name):
                        return True

        sids = set(map(lambda x: (x['sid'],x['authenticated']), filter(match, attrs)))

        for i in Subscription.find_by_sids_and_class(self.env, sids, klass):
            yield i.subscription_tuple()
Exemple #40
0
    def render_preference_panel(self, req, panel, path_info=None):
        if req.method == 'POST':
            method_arg = req.args.get('method', '')
            m = re.match('^([^_]+)_(.+)', method_arg)
            if m:
                method, arg = m.groups()
                method_func = self.post_handlers.get(method)
                if method_func:
                    method_func(arg, req)
                else:
                    pass
            else:
                pass
            # Refresh page after saving changes.
            req.redirect(req.href.prefs('subscriptions'))

        data = {
            'rules': {},
            'subscribers': [],
            'formatters': ('text/plain', 'text/html'),
            'selected_format': {},
            'adverbs': ('always', 'never')
        }

        desc_map = {}

        for i in self.subscribers:
            if not i.description():
                continue
            if not req.session.authenticated and i.requires_authentication():
                continue
            data['subscribers'].append({
                'class': i.__class__.__name__,
                'description': i.description()
            })
            desc_map[i.__class__.__name__] = i.description()

        for i in self.distributors:
            for j in i.transports():
                data['rules'][j] = []
                for r in Subscription.find_by_sid_and_distributor(
                        self.env, req.session.sid, req.session.authenticated,
                        j):
                    if desc_map.get(r['class']):
                        data['rules'][j].append({
                            'id':
                            r['id'],
                            'adverb':
                            r['adverb'],
                            'description':
                            desc_map[r['class']],
                            'priority':
                            r['priority']
                        })
                        data['selected_format'][j] = r['format']

        data['default_rules'] = {}
        defaults = []
        for i in self.default_subscribers:
            defaults.extend(i.default_subscriptions())

        for r in sorted(defaults, key=operator.itemgetter(2)):
            klass, dist, _, adverb = r
            if not data['default_rules'].get(dist):
                data['default_rules'][dist] = []
            if desc_map.get(klass):
                data['default_rules'][dist].append({
                    'adverb':
                    adverb,
                    'description':
                    desc_map.get(klass)
                })

        add_stylesheet(req, 'announcer/css/announcer_prefs.css')
        if hasattr(Chrome(self.env), 'jenv'):
            return 'prefs_announcer_manage_subscriptions.html', dict(
                data=data), None
        else:
            return 'prefs_announcer_manage_subscriptions.html', dict(data=data)
Exemple #41
0
 def _delete_rule(self, arg, req):
     Subscription.delete(self.env, arg)
Exemple #42
0
 def _move_rule(self, arg, req):
     (rule_id, new_priority) = arg.split('-')
     if int(new_priority) >= 1:
         Subscription.move(self.env, rule_id, int(new_priority))
Exemple #43
0
 def _set_format(self, arg, req):
     Subscription.update_format_by_distributor_and_sid(
         self.env, arg, req.session.sid, req.session.authenticated,
         req.args['format-%s' % arg])
Exemple #44
0
 def _set_format(self, arg, req):
     Subscription.update_format_by_distributor_and_sid(self.env, arg,
             req.session.sid, req.session.authenticated,
             req.args['format-%s'%arg])
Exemple #45
0
 def _move_rule(self, arg, req):
     (rule_id, new_priority) = arg.split('-')
     if int(new_priority) >= 1:
         Subscription.move(self.env, rule_id, int(new_priority))
Exemple #46
0
    def render_preference_panel(self, req, panel, path_info=None):
        if req.method == 'POST':
            method_arg = req.args.get('method', '')
            m = re.match('^([^_]+)_(.+)', method_arg)
            if m:
                method, arg = m.groups()
                method_func = self.post_handlers.get(method)
                if method_func:
                    method_func(arg, req)
                else:
                    pass
            else:
                pass
            req.redirect(req.href.prefs('subscriptions'))

        data = {'rules':{}, 'subscribers':[]}

        desc_map = {}

        data['formatters'] = ('text/plain', 'text/html')
        data['selected_format'] = {}
        data['adverbs'] = ('always', 'never')

        for i in self.subscribers:
            if not i.description():
                continue
            if not req.session.authenticated and i.requires_authentication():
                continue
            data['subscribers'].append({
                'class': i.__class__.__name__,
                'description': i.description()
            })
            desc_map[i.__class__.__name__] = i.description()


        for i in self.distributors:
            for j in i.transports():
                data['rules'][j] = []
                for r in Subscription.find_by_sid_and_distributor(self.env,
                        req.session.sid, req.session.authenticated, j):
                    if desc_map.get(r['class']):
                        data['rules'][j].append({
                            'id': r['id'],
                            'adverb': r['adverb'],
                            'description': desc_map[r['class']],
                            'priority': r['priority']
                        })
                        data['selected_format'][j] = r['format']

        data['default_rules'] = {}
        defaults = []
        for i in self.default_subscribers:
            defaults.extend(i.default_subscriptions())

        for r in sorted(defaults, key=itemgetter(2)):
            klass, dist, _, adverb = r
            if not data['default_rules'].get(dist):
                data['default_rules'][dist] = []
            if desc_map.get(klass):
                data['default_rules'][dist].append({
                    'adverb': adverb,
                    'description': desc_map.get(klass)
                })

        add_stylesheet(req, 'announcer/css/announcer_prefs.css')
        return "prefs_announcer_manage_subscriptions.html", dict(data=data)
Exemple #47
0
 def _delete_rule(self, arg, req):
     Subscription.delete(self.env, arg)