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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
__metaclass__ = type
__all__ = [
'DistroArchSeriesActionMenu',
'DistroArchSeriesAddView',
'DistroArchSeriesAdminView',
'DistroArchSeriesBreadcrumb',
'DistroArchSeriesPackageSearchView',
'DistroArchSeriesNavigation',
'DistroArchSeriesView',
]
from lazr.restful.utils import smartquote
from zope.interface import (
implements,
Interface,
)
from lp import _
from lp.app.browser.launchpadform import (
action,
LaunchpadFormView,
)
from lp.services.webapp import (
GetitemNavigation,
LaunchpadEditFormView,
)
from lp.services.webapp.breadcrumb import Breadcrumb
from lp.services.webapp.menu import (
enabled_with_permission,
Link,
NavigationMenu,
)
from lp.services.webapp.publisher import canonical_url
from lp.soyuz.browser.packagesearch import PackageSearchViewBase
from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries
class DistroArchSeriesNavigation(GetitemNavigation):
usedfor = IDistroArchSeries
class DistroArchSeriesBreadcrumb(Breadcrumb):
"""Builds a breadcrumb for `DistroArchSeries`."""
@property
def text(self):
return self.context.architecturetag
class IDistroArchSeriesActionMenu(Interface):
"""Marker interface for the action menu."""
class DistroArchSeriesActionMenu(NavigationMenu):
"""Action menu for distro arch series."""
usedfor = IDistroArchSeriesActionMenu
facet = "overview"
links = ['admin', 'builds']
@enabled_with_permission('launchpad.Admin')
def admin(self):
text = 'Administer'
return Link('+admin', text, icon='edit')
# Search link not necessary, because there's a search form on
# the overview page.
def builds(self):
text = 'Show builds'
return Link('+builds', text, icon='info')
class DistroArchSeriesPackageSearchView(PackageSearchViewBase):
"""Customised PackageSearchView for DistroArchSeries"""
def contextSpecificSearch(self):
"""See `AbstractPackageSearchView`."""
return self.context.searchBinaryPackages(self.text)
class DistroArchSeriesView(DistroArchSeriesPackageSearchView):
"""Default DistroArchSeries view class."""
implements(IDistroArchSeriesActionMenu)
@property
def page_title(self):
return self.context.title
class DistroArchSeriesAddView(LaunchpadFormView):
schema = IDistroArchSeries
field_names = ['architecturetag', 'processorfamily', 'official',
'supports_virtualized']
@property
def label(self):
"""See `LaunchpadFormView`"""
return 'Add a port of %s' % self.context.title
@property
def page_title(self):
"""The page title."""
return self.label
@property
def cancel_url(self):
"""See `LaunchpadFormView`."""
return canonical_url(self.context)
@action(_('Continue'), name='continue')
def create_action(self, action, data):
"""Create a new Port."""
distroarchseries = self.context.newArch(
data['architecturetag'], data['processorfamily'],
data['official'], self.user, data['supports_virtualized'])
self.next_url = canonical_url(distroarchseries)
class DistroArchSeriesAdminView(LaunchpadEditFormView):
"""View class for admin of DistroArchSeries."""
schema = IDistroArchSeries
field_names = [
'architecturetag', 'official', 'supports_virtualized',
'enabled',
]
@action(_('Change'), name='update')
def change_details(self, action, data):
"""Update with details from the form."""
modified = self.updateContextFromData(data)
if modified:
self.request.response.addNotification(
"Successfully updated")
return modified
@property
def next_url(self):
return canonical_url(self.context)
@property
def cancel_url(self):
return self.next_url
@property
def page_title(self):
return smartquote("Administer %s" % self.context.title)
@property
def label(self):
return self.page_title
|