~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-06-06 02:52:27 UTC
  • mfrom: (13144.2.13 picker-click-item-detail)
  • Revision ID: launchpad@pqm.canonical.com-20110606025227-eplcb04k4ucufktz
[r=sinzui][bug=791116] Display links to a person's home page in
 launchpad when displaying search results in a person picker.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    'IHasAffiliation',
21
21
    ]
22
22
 
 
23
from collections import namedtuple
 
24
 
23
25
from zope.component import adapter
24
26
from zope.interface import (
25
27
    implements,
26
28
    Interface,
27
29
    )
28
30
 
 
31
from canonical.launchpad.interfaces.launchpad import IHasIcon
29
32
from lp.bugs.interfaces.bugtask import IBugTask
30
33
 
31
34
 
33
36
    """The affiliation status of a person with a context."""
34
37
 
35
38
    def getAffiliationBadge(person):
36
 
        """Return the badge name for the type of affiliation the person has.
 
39
        """Return the badge for the type of affiliation the person has.
 
40
 
 
41
        The return value is a tuple: (url, alt).
37
42
 
38
43
        If the person has no affiliation with this object, return None.
39
44
        """
40
45
 
 
46
BadgeDetails = namedtuple('BadgeDetails', ('url', 'alt_text'))
 
47
 
41
48
 
42
49
@adapter(Interface)
43
50
class PillarAffiliation(object):
67
74
        affiliated = person.inTeam(pillar.owner)
68
75
        if not affiliated:
69
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
        
70
84
        if self.context.distribution or self.context.distroseries:
71
 
            return "distribution-badge"
 
85
            icon_url = getIconUrl(
 
86
                self.context.distribution or self.context.distroseries.distribution,
 
87
                "/@@/distribution-badge")
 
88
            return BadgeDetails(icon_url, "Affiliated with Ubuntu")
72
89
        if self.context.product or self.context.productseries:
73
 
            return "product-badge"
 
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")