~launchpad-pqm/launchpad/devel

7675.293.15 by Aaron Bentley
Get the reassign view under test.
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
"""Views, navigation and actions for CodeReviewVotes."""
5
6
__metaclass__ = type
7
8
9
from zope.interface import Interface
10
11
from canonical.launchpad import _
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
12
from canonical.launchpad.webapp import (
11929.9.1 by Tim Penhey
Move launchpadform into lp.app.browser.
13
    canonical_url,
14
    )
15
from lp.app.browser.launchpadform import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
16
    action,
17
    LaunchpadFormView,
18
    )
19
from lp.code.errors import (
20
    ReviewNotPending,
21
    UserHasExistingReview,
22
    )
11318.5.1 by j.c.sackett
Migrated canonical.launchpad.fields to lp.services.fields
23
from lp.services.fields import PublicPersonChoice
7675.293.15 by Aaron Bentley
Get the reassign view under test.
24
25
26
class ReassignSchema(Interface):
7675.293.19 by Aaron Bentley
Cleanup
27
    """Schema to use when reassigning the reviewer for a requested review."""
7675.293.15 by Aaron Bentley
Get the reassign view under test.
28
11624.1.1 by Ian Booth
Add cancel url to reassign code view page
29
    reviewer = PublicPersonChoice(title=_('Reviewer'), required=True,
7675.293.15 by Aaron Bentley
Get the reassign view under test.
30
            description=_('A person who you want to review this.'),
31
            vocabulary='ValidPersonOrTeam')
32
33
34
class CodeReviewVoteReassign(LaunchpadFormView):
7675.293.19 by Aaron Bentley
Cleanup
35
    """View for reassinging the reviewer for a requested review."""
7675.293.15 by Aaron Bentley
Get the reassign view under test.
36
37
    schema = ReassignSchema
38
9209.1.10 by Tim Penhey
Use generic-edit instead of reviewrequest_reassign.
39
    page_title = label = 'Reassign review request'
40
11624.1.2 by Ian Booth
Fixes as per code review
41
    @property
42
    def next_url(self):
43
        return canonical_url(self.context.branch_merge_proposal)
44
45
    cancel_url = next_url
11624.1.1 by Ian Booth
Add cancel url to reassign code view page
46
7675.293.15 by Aaron Bentley
Get the reassign view under test.
47
    @action('Reassign', name='reassign')
48
    def reassign_action(self, action, data):
7675.293.19 by Aaron Bentley
Cleanup
49
        """Use the form data to change the review request reviewer."""
7675.429.14 by Tim Penhey
Move the method into the model.
50
        self.context.reassignReview(data['reviewer'])
7675.429.18 by Tim Penhey
Add some validators.
51
52
    def validate(self, data):
53
        """Make sure that the reassignment can happen."""
54
        reviewer = data.get('reviewer')
55
        if reviewer is not None:
7675.429.19 by Tim Penhey
Update the story for reassignment.
56
            try:
57
                self.context.validateReasignReview(reviewer)
58
            except (ReviewNotPending, UserHasExistingReview), e:
59
                self.addError(str(e))