1
# Copyright 2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Adapters to figure out affiliations between people and pillars/bugs etc.
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
12
The adapters herein are provided for various contexts so that for a given
13
person, the relevant affiliation details may be determined.
23
from collections import namedtuple
25
from zope.component import adapter
26
from zope.interface import (
31
from canonical.launchpad.interfaces.launchpad import IHasIcon
32
from lp.bugs.interfaces.bugtask import IBugTask
35
class IHasAffiliation(Interface):
36
"""The affiliation status of a person with a context."""
38
def getAffiliationBadge(person):
39
"""Return the badge for the type of affiliation the person has.
41
The return value is a tuple: (url, alt).
43
If the person has no affiliation with this object, return None.
46
BadgeDetails = namedtuple('BadgeDetails', ('url', 'alt_text'))
50
class PillarAffiliation(object):
51
"""Default affiliation adapter.
53
No affiliation is returned.
56
implements(IHasAffiliation)
58
def __init__(self, context):
59
self.context = context
61
def getAffiliationBadge(self, person):
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..
69
class BugTaskPillarAffiliation(PillarAffiliation):
70
"""An affiliation adapter for bug tasks."""
72
def getAffiliationBadge(self, person):
73
pillar = self.context.pillar
74
affiliated = person.inTeam(pillar.owner)
78
def getIconUrl(context, default_url):
79
if IHasIcon.providedBy(context) and context.icon is not None:
80
icon_url = context.icon.getURL()
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,
93
return BadgeDetails(icon_url, "Affiliated with Launchpad itself")