~launchpad-pqm/launchpad/devel

8687.15.15 by Karl Fogel
Add the copyright header block to files under lib/lp/bugs/.
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3283.3.1 by Brad Bollenbach
create a new branch for bzr integration, to avoid 3 hour merge time
3
4
"""Browser view classes for BugBranch-related objects."""
5
6
__metaclass__ = type
3283.3.2 by Brad Bollenbach
fixes based on talking to the sab this morning. tightening up the security model a bit by basing privileges on an IHasBug interface.
7
__all__ = [
8339.2.12 by Paul Hummer
Fixed everything from the review but the oops
8
    'BranchLinkToBugView',
9
    'BugBranchAddView',
8339.2.15 by Paul Hummer
Removed unneeded views, tested through various flows
10
    'BugBranchDeleteView',
6998.1.1 by Tim Penhey
Update the primary contexts for branch merge proposals, branch subscriptions, code review comments, and bug branch links.
11
    'BugBranchPrimaryContext',
9691.7.2 by Tim Penhey
Give the bug branch a view, and ready the template for the merge proposal rendering.
12
    'BugBranchView',
4789.3.1 by Tim Penhey
First cut.
13
    ]
3283.3.2 by Brad Bollenbach
fixes based on talking to the sab this morning. tightening up the security model a bit by basing privileges on an IHasBug interface.
14
8971.31.4 by Graham Binns
BugBranches are now added to the linked branches list as they're linked.
15
from lazr.restful.interfaces import IWebServiceClientRequest
13931.2.1 by Steve Kowalik
Chip away at canonical.lazr a little more.
16
from lazr.restful.utils import smartquote
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
17
from zope.component import (
18
    adapts,
19
    getMultiAdapter,
20
    )
21
from zope.interface import (
22
    implements,
23
    Interface,
24
    )
3283.3.1 by Brad Bollenbach
create a new branch for bzr integration, to avoid 3 hour merge time
25
14600.1.12 by Curtis Hovey
Move i18n to lp.
26
from lp import _
11929.9.1 by Tim Penhey
Move launchpadform into lp.app.browser.
27
from lp.app.browser.launchpadform import (
28
    action,
29
    LaunchpadEditFormView,
30
    LaunchpadFormView,
31
    )
9084.1.2 by Tim Penhey
Weird sizing on the inpage linking view.
32
from lp.bugs.interfaces.bugbranch import IBugBranch
9691.7.10 by Tim Penhey
make the links work on the bug page.
33
from lp.code.browser.branchmergeproposal import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
34
    latest_proposals_for_each_branch,
35
    )
9691.7.2 by Tim Penhey
Give the bug branch a view, and ready the template for the merge proposal rendering.
36
from lp.code.enums import BranchLifecycleStatus
11382.6.34 by Gavin Panella
Reformat imports in all files touched so far.
37
from lp.services.propertycache import cachedproperty
14612.2.1 by William Grant
format-imports on lib/. So many imports.
38
from lp.services.webapp import (
39
    canonical_url,
40
    LaunchpadView,
41
    )
42
from lp.services.webapp.interfaces import IPrimaryContext
3283.3.1 by Brad Bollenbach
create a new branch for bzr integration, to avoid 3 hour merge time
43
4789.4.8 by Tim Penhey
Removed old status view, made inline edits of bug branch links.
44
6998.1.1 by Tim Penhey
Update the primary contexts for branch merge proposals, branch subscriptions, code review comments, and bug branch links.
45
class BugBranchPrimaryContext:
46
    """The primary context is the bug branch link is that of the branch."""
47
48
    implements(IPrimaryContext)
49
50
    def __init__(self, bug_branch):
51
        self.context = IPrimaryContext(bug_branch.branch).context
52
53
5001.1.4 by Tim Penhey
Added registrants to BugBranch and SpecificationBranch.
54
class BugBranchAddView(LaunchpadFormView):
3283.3.1 by Brad Bollenbach
create a new branch for bzr integration, to avoid 3 hour merge time
55
    """Browser view for linking a bug to a branch."""
5001.1.4 by Tim Penhey
Added registrants to BugBranch and SpecificationBranch.
56
    schema = IBugBranch
57
    # In order to have the branch field rendered using the appropriate
58
    # widget, we set the LaunchpadFormView attribute for_input to True
59
    # to get the read only fields rendered as input widgets.
5099.10.9 by Tim Penhey
Updates following review.
60
    for_input = True
14433.2.24 by Curtis Hovey
Moved page_title into view.
61
    page_title = 'Add branch'
8339.2.3 by Paul Hummer
Did my best to remove traces of the whiteboard
62
    field_names = ['branch']
5001.1.4 by Tim Penhey
Added registrants to BugBranch and SpecificationBranch.
63
5099.10.5 by Tim Penhey
Some drive by clean up making buttons and links consistent.
64
    @action(_('Continue'), name='continue')
5001.1.4 by Tim Penhey
Added registrants to BugBranch and SpecificationBranch.
65
    def continue_action(self, action, data):
66
        branch = data['branch']
8698.10.4 by Paul Hummer
Fixed references to broken code
67
        self.context.bug.linkBranch(
8339.2.3 by Paul Hummer
Did my best to remove traces of the whiteboard
68
            branch=branch, registrant=self.user)
3283.3.1 by Brad Bollenbach
create a new branch for bzr integration, to avoid 3 hour merge time
69
        self.request.response.addNotification(
70
            "Successfully registered branch %s for this bug." %
71
            branch.name)
72
5001.1.11 by Tim Penhey
Minor update needed due to view base class changing.
73
    @property
74
    def next_url(self):
3283.3.1 by Brad Bollenbach
create a new branch for bzr integration, to avoid 3 hour merge time
75
        return canonical_url(self.context)
3283.3.2 by Brad Bollenbach
fixes based on talking to the sab this morning. tightening up the security model a bit by basing privileges on an IHasBug interface.
76
9225.2.5 by Abel Deuring
moved the heading of the page into BugBranchAddView.label
77
    @property
78
    def label(self):
79
        return 'Add a branch to bug #%i' % self.context.bug.id
80
6918.1.1 by Gavin Panella
Use the correct type of cancel button/link.
81
    cancel_url = next_url
82
3283.3.2 by Brad Bollenbach
fixes based on talking to the sab this morning. tightening up the security model a bit by basing privileges on an IHasBug interface.
83
8339.2.13 by Paul Hummer
Removed the need for bug-branch edit, substiting for delete
84
class BugBranchDeleteView(LaunchpadEditFormView):
85
    """View to update a BugBranch."""
86
    schema = IBugBranch
87
8339.2.22 by Paul Hummer
Fix broken tests
88
    field_names = []
8339.2.13 by Paul Hummer
Removed the need for bug-branch edit, substiting for delete
89
90
    def initialize(self):
91
        LaunchpadEditFormView.initialize(self)
92
93
    @property
94
    def next_url(self):
8339.2.22 by Paul Hummer
Fix broken tests
95
        return canonical_url(self.context.bug)
8339.2.13 by Paul Hummer
Removed the need for bug-branch edit, substiting for delete
96
8339.2.15 by Paul Hummer
Removed unneeded views, tested through various flows
97
    cancel_url = next_url
98
12126.1.3 by j.c.sackett
'Remove link' sounds better than 'unlink'
99
    @action('Remove link', name='delete')
8339.2.15 by Paul Hummer
Removed unneeded views, tested through various flows
100
    def delete_action(self, action, data):
8698.10.4 by Paul Hummer
Fixed references to broken code
101
        self.context.bug.unlinkBranch(self.context.branch, self.user)
8339.2.6 by Paul Hummer
All whiteboards for BugBranch are gone!
102
9254.3.3 by Abel Deuring
implemented more reviewer's comments
103
    label = 'Remove bug branch link'
9254.3.1 by Abel Deuring
bugbranch-delete.pt switched to LP 3 layout
104
8339.2.6 by Paul Hummer
All whiteboards for BugBranch are gone!
105
9691.7.2 by Tim Penhey
Give the bug branch a view, and ready the template for the merge proposal rendering.
106
class BugBranchView(LaunchpadView):
107
    """Simple view to cache related branch information."""
108
109
    @cachedproperty
9691.7.10 by Tim Penhey
make the links work on the bug page.
110
    def merge_proposals(self):
9691.7.2 by Tim Penhey
Give the bug branch a view, and ready the template for the merge proposal rendering.
111
        """Return a list of active proposals for the branch."""
9691.7.10 by Tim Penhey
make the links work on the bug page.
112
        branch = self.context.branch
14414.2.3 by Ian Booth
Fix implementation and add tests
113
        return latest_proposals_for_each_branch(branch.landing_targets)
9691.7.2 by Tim Penhey
Give the bug branch a view, and ready the template for the merge proposal rendering.
114
115
    @property
116
    def show_branch_status(self):
117
        """Show the branch status if merged and there are no proposals."""
12126.1.4 by j.c.sackett
Lint fixes.
118
        lifecycle_status = self.context.branch.lifecycle_status
9691.7.10 by Tim Penhey
make the links work on the bug page.
119
        return (len(self.merge_proposals) == 0 and
12126.1.4 by j.c.sackett
Lint fixes.
120
                lifecycle_status == BranchLifecycleStatus.MERGED)
9691.7.2 by Tim Penhey
Give the bug branch a view, and ready the template for the merge proposal rendering.
121
122
4789.3.1 by Tim Penhey
First cut.
123
class BranchLinkToBugView(LaunchpadFormView):
4789.3.5 by Tim Penhey
Updates following review.
124
    """The view to create bug-branch links."""
4789.3.1 by Tim Penhey
First cut.
125
    schema = IBugBranch
4789.3.8 by Tim Penhey
Added comment to for_input
126
    # In order to have the bug field rendered using the appropriate
127
    # widget, we set the LaunchpadFormView attribute for_input to True
128
    # to get the read only fields rendered as input widgets.
5099.10.9 by Tim Penhey
Updates following review.
129
    for_input = True
4789.3.1 by Tim Penhey
First cut.
130
8339.2.3 by Paul Hummer
Did my best to remove traces of the whiteboard
131
    field_names = ['bug']
4789.3.1 by Tim Penhey
First cut.
132
5099.10.5 by Tim Penhey
Some drive by clean up making buttons and links consistent.
133
    @property
9084.1.2 by Tim Penhey
Weird sizing on the inpage linking view.
134
    def label(self):
135
        return "Link to a bug report"
136
137
    @property
138
    def page_title(self):
139
        return smartquote(
140
            'Link branch "%s" to a bug report' % self.context.displayname)
141
142
    @property
5099.10.5 by Tim Penhey
Some drive by clean up making buttons and links consistent.
143
    def next_url(self):
144
        return canonical_url(self.context)
145
9084.1.2 by Tim Penhey
Weird sizing on the inpage linking view.
146
    cancel_url = next_url
147
5099.10.5 by Tim Penhey
Some drive by clean up making buttons and links consistent.
148
    @action(_('Continue'), name='continue')
149
    def continue_action(self, action, data):
4789.3.1 by Tim Penhey
First cut.
150
        bug = data['bug']
11929.9.1 by Tim Penhey
Move launchpadform into lp.app.browser.
151
        bug.linkBranch(branch=self.context, registrant=self.user)
8971.31.4 by Graham Binns
BugBranches are now added to the linked branches list as they're linked.
152
153
154
class BugBranchXHTMLRepresentation:
155
    adapts(IBugBranch, IWebServiceClientRequest)
156
    implements(Interface)
157
8971.31.11 by Graham Binns
Review fixes for intellectronica.
158
    def __init__(self, branch, request):
159
        self.branch = branch
8971.31.4 by Graham Binns
BugBranches are now added to the linked branches list as they're linked.
160
        self.request = request
161
162
    def __call__(self):
163
        """Render `BugBranch` as XHTML using the webservice."""
8971.31.11 by Graham Binns
Review fixes for intellectronica.
164
        branch_view = getMultiAdapter(
165
            (self.branch, self.request), name="+bug-branch")
166
        return branch_view()