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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Shared menus."""
__metaclass__ = type
__all__ = [
'IRegistryCollectionNavigationMenu',
'RegistryCollectionActionMenuBase',
'RegistryCollectionNavigationMenu',
'TopLevelMenuMixin',
]
from zope.interface import Interface
from canonical.launchpad.webapp.menu import (
enabled_with_permission,
Link,
NavigationMenu,
)
class TopLevelMenuMixin:
"""Menu shared by top level collection objects."""
def projects(self):
return Link('/projects/', 'View projects', icon='info')
def distributions(self):
return Link('/distros/', 'View distributions', icon='info')
def people(self):
return Link('/people/', 'View people', icon='info')
def meetings(self):
return Link('/sprints/', 'View meetings', icon='info')
def project_groups(self):
return Link('/projectgroups', 'View project groups', icon='info')
def register_project(self):
text = 'Register a project'
return Link('/projects/+new', text, icon='add')
def register_team(self):
text = 'Register a team'
return Link('/people/+newteam', text, icon='add')
@enabled_with_permission('launchpad.Admin')
def register_distribution(self):
text = 'Register a distribution'
return Link('/distros/+add', text, icon='add')
def create_account(self):
text = 'Create an account'
# Only enable this link for anonymous users.
enabled = self.user is None
return Link('/people/+login', text, icon='add', enabled=enabled)
@enabled_with_permission('launchpad.View')
def request_merge(self):
text = 'Request a merge'
return Link('/people/+requestmerge', text, icon='edit')
@enabled_with_permission('launchpad.Admin')
def admin_merge_people(self):
text = 'Merge people'
return Link('/people/+adminpeoplemerge', text, icon='edit')
@enabled_with_permission('launchpad.Moderate')
def admin_merge_teams(self):
text = 'Merge teams'
return Link('/people/+adminteammerge', text, icon='edit')
class IRegistryCollectionNavigationMenu(Interface):
"""Marker interface for top level registry collection navigation menu."""
class RegistryCollectionNavigationMenu(NavigationMenu, TopLevelMenuMixin):
"""Navigation menu for top level registry collections."""
usedfor = IRegistryCollectionNavigationMenu
facet = 'overview'
links = [
'projects',
'project_groups',
'distributions',
'people',
'meetings',
]
class RegistryCollectionActionMenuBase(NavigationMenu, TopLevelMenuMixin):
"""Action menu for top level registry collections.
Because of the way menus work, you need to subclass this menu class and
set the `usedfor` attribute on the subclass. `usedfor` should point to
the interface of the context object, so we can't do that for you.
You should also set the `links` attribute to get just the menu items you
want for the collection's overview page.
"""
facet = 'overview'
|