1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Views, menus and traversal related to PersonProducts."""
__metaclass__ = type
__all__ = [
'PersonProductBreadcrumb',
'PersonProductFacets',
'PersonProductNavigation',
]
from zope.component import queryAdapter
from zope.traversing.interfaces import IPathAdapter
from lp.services.webapp import (
Link,
Navigation,
StandardLaunchpadFacets,
)
from lp.services.webapp.breadcrumb import Breadcrumb
from lp.app.errors import NotFoundError
from lp.code.interfaces.branchnamespace import get_branch_namespace
from lp.registry.interfaces.personproduct import IPersonProduct
class PersonProductNavigation(Navigation):
"""Navigation to branches for this person/product."""
usedfor = IPersonProduct
def traverse(self, branch_name):
"""Look for a branch in the person/product namespace."""
namespace = get_branch_namespace(
person=self.context.person, product=self.context.product)
branch = namespace.getByName(branch_name)
if branch is None:
raise NotFoundError
else:
return branch
class PersonProductBreadcrumb(Breadcrumb):
"""Breadcrumb for an `IPersonProduct`."""
@property
def text(self):
return self.context.product.displayname
@property
def icon(self):
return queryAdapter(
self.context.product, IPathAdapter, name='image').icon()
class PersonProductFacets(StandardLaunchpadFacets):
"""The links that will appear in the facet menu for an IPerson."""
usedfor = IPersonProduct
enable_only = ['branches']
def branches(self):
text = 'Code'
summary = ('Bazaar Branches of %s owned by %s' %
(self.context.product.displayname,
self.context.person.displayname))
return Link('', text, summary)
|