~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/browser/branchsubscription.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-04-12 13:17:34 UTC
  • mfrom: (12775.3.11 bug-736002)
  • Revision ID: launchpad@pqm.canonical.com-20110412131734-td8mjeehq8z93uzs
[r=jtv][bug=736002] Speed up +bugtarget-portlet-tags-content.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
__metaclass__ = type
12
12
    'BranchSubscriptionPrimaryContext',
13
13
    ]
14
14
 
15
 
from lazr.restful.utils import smartquote
 
15
 
16
16
from zope.interface import implements
17
17
 
 
18
from canonical.launchpad.webapp import (
 
19
    canonical_url,
 
20
    LaunchpadView,
 
21
    )
 
22
from canonical.launchpad.webapp.authorization import check_permission
 
23
from canonical.launchpad.webapp.interfaces import IPrimaryContext
 
24
from canonical.launchpad.webapp.menu import structured
 
25
from canonical.lazr.utils import smartquote
18
26
from lp.app.browser.launchpadform import (
19
27
    action,
20
28
    LaunchpadEditFormView,
22
30
    )
23
31
from lp.code.enums import BranchSubscriptionNotificationLevel
24
32
from lp.code.interfaces.branchsubscription import IBranchSubscription
25
 
from lp.services.webapp import (
26
 
    canonical_url,
27
 
    LaunchpadView,
28
 
    )
29
 
from lp.services.webapp.authorization import (
30
 
    check_permission,
31
 
    precache_permission_for_objects,
32
 
    )
33
 
from lp.services.webapp.interfaces import IPrimaryContext
34
 
from lp.services.webapp.menu import structured
35
33
 
36
34
 
37
35
class BranchSubscriptionPrimaryContext:
51
49
 
52
50
    def subscriptions(self):
53
51
        """Return a decorated list of branch subscriptions."""
54
 
 
55
 
        # Cache permissions so private subscribers can be rendered.
56
 
        # The security adaptor will do the job also but we don't want or need
57
 
        # the expense of running several complex SQL queries.
58
 
        if self.user is not None:
59
 
            subscribers = [
60
 
                subscription.person
61
 
                for subscription in self.context.subscriptions]
62
 
            precache_permission_for_objects(
63
 
                self.request, "launchpad.LimitedView", subscribers)
64
 
 
65
52
        visible_subscriptions = [
66
53
            subscription for subscription in self.context.subscriptions
67
 
            if check_permission('launchpad.LimitedView', subscription.person)]
 
54
            if check_permission('launchpad.View', subscription.person)]
68
55
        return sorted(
69
56
            visible_subscriptions,
70
57
            key=lambda subscription: subscription.person.displayname)
284
271
        return canonical_url(self.branch)
285
272
 
286
273
    cancel_url = next_url
 
274