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
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Specification views."""
__metaclass__ = type
__all__ = [
'BranchLinkToSpecificationView',
'SpecificationBranchBranchInlineEditView',
'SpecificationBranchStatusView',
'SpecificationBranchURL',
]
from lazr.restful.utils import smartquote
from zope.interface import implements
from canonical.launchpad import _
from canonical.launchpad.webapp import (
canonical_url,
)
from canonical.launchpad.webapp.interfaces import ICanonicalUrlData
from lp.app.browser.launchpadform import (
action,
LaunchpadEditFormView,
LaunchpadFormView,
)
from lp.blueprints.interfaces.specificationbranch import ISpecificationBranch
class SpecificationBranchURL:
"""Specification branch URL creation rules."""
implements(ICanonicalUrlData)
rootsite = "blueprints"
def __init__(self, specification_branch):
self.branch = specification_branch.branch
self.specification = specification_branch.specification
@property
def inside(self):
return self.specification
@property
def path(self):
return u'+branch/%s' % self.branch.unique_name[1:]
class SpecificationBranchStatusView(LaunchpadEditFormView):
"""Edit the summary of the SpecificationBranch link."""
schema = ISpecificationBranch
field_names = []
label = _('Delete link between specification and branch')
def initialize(self):
self.specification = self.context.specification
super(SpecificationBranchStatusView, self).initialize()
@property
def next_url(self):
return canonical_url(self.specification)
@action(_('Delete'), name='delete')
def delete_action(self, action, data):
self.context.destroySelf()
class SpecificationBranchBranchInlineEditView(SpecificationBranchStatusView):
"""Inline edit view for specification branch details.
This view is used to control the in page editing from the branch page.
"""
initial_focus_widget = None
label = None
def initialize(self):
self.branch = self.context.branch
super(SpecificationBranchBranchInlineEditView, self).initialize()
@property
def prefix(self):
return "field%s" % self.context.id
@property
def action_url(self):
return "%s/+branch-edit" % canonical_url(self.context)
@property
def next_url(self):
return canonical_url(self.branch)
class BranchLinkToSpecificationView(LaunchpadFormView):
"""The view to create spec-branch links."""
schema = ISpecificationBranch
# In order to have the specification field rendered using the appropriate
# widget, we set the LaunchpadFormView attribute for_input to True
# to get the read only fields rendered as input widgets.
for_input = True
field_names = ['specification']
@property
def label(self):
return "Link to a blueprint"
@property
def page_title(self):
return smartquote(
'Link branch "%s" to a blueprint' % self.context.displayname)
@property
def next_url(self):
return canonical_url(self.context)
cancel_url = next_url
@action(_('Continue'), name='continue')
def continue_action(self, action, data):
spec = data['specification']
spec.linkBranch(branch=self.context, registrant=self.user)
|