~launchpad-pqm/launchpad/devel

9109.1.10 by Barry Warsaw
Refactor the top level context menu into a mixin and use that on the /products
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
"""Shared menus."""
5
6
__metaclass__ = type
7
__all__ = [
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
8
    'IRegistryCollectionNavigationMenu',
9109.1.20 by Barry Warsaw
* add PersonSetNavigationMenu as the action menu for the page
9
    'RegistryCollectionActionMenuBase',
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
10
    'RegistryCollectionNavigationMenu',
9109.1.14 by Barry Warsaw
Renames:
11
    'TopLevelMenuMixin',
9109.1.10 by Barry Warsaw
Refactor the top level context menu into a mixin and use that on the /products
12
    ]
13
14
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
15
from zope.interface import Interface
16
9109.1.25 by Barry Warsaw
s/PersonSetNavigationMenu/PersonSetActionNavigationMenu/
17
from canonical.launchpad.webapp.menu import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
18
    enabled_with_permission,
19
    Link,
20
    NavigationMenu,
21
    )
9109.1.14 by Barry Warsaw
Renames:
22
23
24
class TopLevelMenuMixin:
25
    """Menu shared by top level collection objects."""
9109.1.10 by Barry Warsaw
Refactor the top level context menu into a mixin and use that on the /products
26
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
27
    def projects(self):
9189.3.1 by Barry Warsaw
Convert /sprints page to UI 3.0.
28
        return Link('/projects/', 'View projects', icon='info')
9109.1.10 by Barry Warsaw
Refactor the top level context menu into a mixin and use that on the /products
29
30
    def distributions(self):
9189.3.1 by Barry Warsaw
Convert /sprints page to UI 3.0.
31
        return Link('/distros/', 'View distributions', icon='info')
9109.1.10 by Barry Warsaw
Refactor the top level context menu into a mixin and use that on the /products
32
33
    def people(self):
9189.3.1 by Barry Warsaw
Convert /sprints page to UI 3.0.
34
        return Link('/people/', 'View people', icon='info')
9109.1.10 by Barry Warsaw
Refactor the top level context menu into a mixin and use that on the /products
35
36
    def meetings(self):
9189.3.1 by Barry Warsaw
Convert /sprints page to UI 3.0.
37
        return Link('/sprints/', 'View meetings', icon='info')
9109.1.10 by Barry Warsaw
Refactor the top level context menu into a mixin and use that on the /products
38
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
39
    def project_groups(self):
9189.3.1 by Barry Warsaw
Convert /sprints page to UI 3.0.
40
        return Link('/projectgroups', 'View project groups', icon='info')
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
41
9109.1.10 by Barry Warsaw
Refactor the top level context menu into a mixin and use that on the /products
42
    def register_project(self):
43
        text = 'Register a project'
9109.1.25 by Barry Warsaw
s/PersonSetNavigationMenu/PersonSetActionNavigationMenu/
44
        return Link('/projects/+new', text, icon='add')
9109.1.10 by Barry Warsaw
Refactor the top level context menu into a mixin and use that on the /products
45
46
    def register_team(self):
47
        text = 'Register a team'
9109.1.25 by Barry Warsaw
s/PersonSetNavigationMenu/PersonSetActionNavigationMenu/
48
        return Link('/people/+newteam', text, icon='add')
9109.1.14 by Barry Warsaw
Renames:
49
12493.3.1 by rvb
Add the 'Register a distribution' link to the distros page.
50
    @enabled_with_permission('launchpad.Admin')
51
    def register_distribution(self):
52
        text = 'Register a distribution'
53
        return Link('/distros/+add', text, icon='add')
54
9109.1.14 by Barry Warsaw
Renames:
55
    def create_account(self):
56
        text = 'Create an account'
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
57
        # Only enable this link for anonymous users.
9109.1.20 by Barry Warsaw
* add PersonSetNavigationMenu as the action menu for the page
58
        enabled = self.user is None
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
59
        return Link('/people/+login', text, icon='add', enabled=enabled)
60
9109.1.25 by Barry Warsaw
s/PersonSetNavigationMenu/PersonSetActionNavigationMenu/
61
    @enabled_with_permission('launchpad.View')
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
62
    def request_merge(self):
63
        text = 'Request a merge'
9109.1.25 by Barry Warsaw
s/PersonSetNavigationMenu/PersonSetActionNavigationMenu/
64
        return Link('/people/+requestmerge', text, icon='edit')
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
65
9109.1.25 by Barry Warsaw
s/PersonSetNavigationMenu/PersonSetActionNavigationMenu/
66
    @enabled_with_permission('launchpad.Admin')
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
67
    def admin_merge_people(self):
68
        text = 'Merge people'
9109.1.25 by Barry Warsaw
s/PersonSetNavigationMenu/PersonSetActionNavigationMenu/
69
        return Link('/people/+adminpeoplemerge', text, icon='edit')
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
70
10163.4.2 by Edwin Grubbs
Show "Merge teams" link to registry experts.
71
    @enabled_with_permission('launchpad.Moderate')
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
72
    def admin_merge_teams(self):
73
        text = 'Merge teams'
9109.1.25 by Barry Warsaw
s/PersonSetNavigationMenu/PersonSetActionNavigationMenu/
74
        return Link('/people/+adminteammerge', text, icon='edit')
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
75
76
77
class IRegistryCollectionNavigationMenu(Interface):
78
    """Marker interface for top level registry collection navigation menu."""
79
80
81
class RegistryCollectionNavigationMenu(NavigationMenu, TopLevelMenuMixin):
9109.1.20 by Barry Warsaw
* add PersonSetNavigationMenu as the action menu for the page
82
    """Navigation menu for top level registry collections."""
9109.1.19 by Barry Warsaw
Addressed many of the review comments:
83
84
    usedfor = IRegistryCollectionNavigationMenu
85
    facet = 'overview'
86
87
    links = [
88
        'projects',
89
        'project_groups',
90
        'distributions',
91
        'people',
92
        'meetings',
93
        ]
9109.1.20 by Barry Warsaw
* add PersonSetNavigationMenu as the action menu for the page
94
95
96
class RegistryCollectionActionMenuBase(NavigationMenu, TopLevelMenuMixin):
97
    """Action menu for top level registry collections.
98
99
    Because of the way menus work, you need to subclass this menu class and
100
    set the `usedfor` attribute on the subclass.  `usedfor` should point to
101
    the interface of the context object, so we can't do that for you.
9157.1.2 by Barry Warsaw
Update /projects to UI 3.0.
102
103
    You should also set the `links` attribute to get just the menu items you
104
    want for the collection's overview page.
9109.1.20 by Barry Warsaw
* add PersonSetNavigationMenu as the action menu for the page
105
    """
106
    facet = 'overview'