~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/model/pillaraffiliation.py

  • Committer: Francis J. Lacoste
  • Date: 2011-04-27 21:40:03 UTC
  • mto: This revision was merged to the branch mainline in revision 12971.
  • Revision ID: francis.lacoste@canonical.com-20110427214003-iiqhcyyswppyqjsx
Change the default timeout to production value, improved options documentation and use only one bin above timeout value.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2011 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
"""Adapters to figure out affiliations between people and pillars/bugs etc.
5
 
 
6
 
When using a person in a given context, for example as a selection item in a
7
 
picker used to choose a bug task assignee, it is important to provide an
8
 
indication as to how that person may be affiliated with the context. Amongst
9
 
other reasons, this provides a visual cue that the correct person is being
10
 
selected for example.
11
 
 
12
 
The adapters herein are provided for various contexts so that for a given
13
 
person, the relevant affiliation details may be determined.
14
 
 
15
 
"""
16
 
 
17
 
__metaclass__ = type
18
 
 
19
 
__all__ = [
20
 
    'IHasAffiliation',
21
 
    ]
22
 
 
23
 
from collections import namedtuple
24
 
 
25
 
from zope.component import adapter
26
 
from zope.interface import (
27
 
    implements,
28
 
    Interface,
29
 
    )
30
 
 
31
 
from canonical.launchpad.interfaces.launchpad import IHasIcon
32
 
from lp.bugs.interfaces.bugtask import IBugTask
33
 
 
34
 
 
35
 
class IHasAffiliation(Interface):
36
 
    """The affiliation status of a person with a context."""
37
 
 
38
 
    def getAffiliationBadge(person):
39
 
        """Return the badge for the type of affiliation the person has.
40
 
 
41
 
        The return value is a tuple: (url, alt).
42
 
 
43
 
        If the person has no affiliation with this object, return None.
44
 
        """
45
 
 
46
 
BadgeDetails = namedtuple('BadgeDetails', ('url', 'alt_text'))
47
 
 
48
 
 
49
 
@adapter(Interface)
50
 
class PillarAffiliation(object):
51
 
    """Default affiliation adapter.
52
 
 
53
 
    No affiliation is returned.
54
 
    """
55
 
 
56
 
    implements(IHasAffiliation)
57
 
 
58
 
    def __init__(self, context):
59
 
        self.context = context
60
 
 
61
 
    def getAffiliationBadge(self, person):
62
 
        return None
63
 
 
64
 
 
65
 
# XXX: wallyworld 2011-05-24 bug=81692: TODO Work is required to determine
66
 
# exactly what is required in terms of figuring out affiliation..
67
 
 
68
 
@adapter(IBugTask)
69
 
class BugTaskPillarAffiliation(PillarAffiliation):
70
 
    """An affiliation adapter for bug tasks."""
71
 
 
72
 
    def getAffiliationBadge(self, person):
73
 
        pillar = self.context.pillar
74
 
        affiliated = person.inTeam(pillar.owner)
75
 
        if not affiliated:
76
 
            return None
77
 
 
78
 
        def getIconUrl(context, default_url):
79
 
            if IHasIcon.providedBy(context) and context.icon is not None:
80
 
                icon_url = context.icon.getURL()
81
 
                return icon_url
82
 
            return default_url
83
 
        
84
 
        if self.context.distribution or self.context.distroseries:
85
 
            icon_url = getIconUrl(
86
 
                self.context.distribution or self.context.distroseries.distribution,
87
 
                "/@@/distribution-badge")
88
 
            return BadgeDetails(icon_url, "Affiliated with Ubuntu")
89
 
        if self.context.product or self.context.productseries:
90
 
            icon_url = getIconUrl(
91
 
                self.context.product or self.context.productseries.product,
92
 
                "/@@/product-badge")
93
 
            return BadgeDetails(icon_url, "Affiliated with Launchpad itself")