~launchpad-pqm/launchpad/devel

14642.1.8 by Curtis Hovey
Updated copyright.
1
# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
8687.15.17 by Karl Fogel
Add the copyright header block to the rest of the files under lib/lp/.
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3691.401.1 by Diogo Matsubara
Fixes bug 62423 (The 'appoint driver' form is broken for projects), adds a common AppointDriverView that will be used by all +driver pages
3
4
"""Browser view class for drivers."""
5
6
__metaclass__ = type
7
__all__ = ["AppointDriverView"]
8
3691.401.10 by Diogo Matsubara
last review comments
9
from zope.interface import providedBy
10
from zope.security.proxy import removeSecurityProxy
11
14642.1.2 by Curtis Hovey
Removed action from webapp globs.
12
from lp.app.browser.launchpadform import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
13
    action,
14
    LaunchpadEditFormView,
15
    )
3691.401.1 by Diogo Matsubara
Fixes bug 62423 (The 'appoint driver' form is broken for projects), adds a common AppointDriverView that will be used by all +driver pages
16
14642.1.2 by Curtis Hovey
Removed action from webapp globs.
17
from lp.registry.interfaces.productseries import IProductSeries
18
from lp.registry.interfaces.role import IHasAppointedDriver
19
from lp.services.webapp.publisher import canonical_url
20
3691.401.8 by Diogo Matsubara
review comments: Refactored the patch to use IHasAppointedDriver
21
3691.401.1 by Diogo Matsubara
Fixes bug 62423 (The 'appoint driver' form is broken for projects), adds a common AppointDriverView that will be used by all +driver pages
22
class AppointDriverView(LaunchpadEditFormView):
3691.401.8 by Diogo Matsubara
review comments: Refactored the patch to use IHasAppointedDriver
23
    """Browser view for appointing a driver to an object."""
24
3691.401.1 by Diogo Matsubara
Fixes bug 62423 (The 'appoint driver' form is broken for projects), adds a common AppointDriverView that will be used by all +driver pages
25
    field_names = ['driver']
26
3691.401.10 by Diogo Matsubara
last review comments
27
    @property
28
    def schema(self):
29
        """Return the schema that is the most specific extension of
30
        IHasAppointedDriver
31
        """
32
        assert IHasAppointedDriver.providedBy(self.context), (
33
            "context should provide IHasAppointedDriver.")
34
        for interface in providedBy(self.context):
35
            if interface.isOrExtends(IHasAppointedDriver):
4664.1.1 by Curtis Hovey
Normalized comments for bug 3732.
36
                # XXX matsubara 2007-02-13 bug=84940:
37
                # removeSecurityProxy() is a workaround.
3691.401.10 by Diogo Matsubara
last review comments
38
                return removeSecurityProxy(interface)
39
8566.2.1 by Curtis Hovey
Use the term 'Release manager' to distinguish the series driver from the project drivers.
40
    @property
41
    def label(self):
42
        """The page heading."""
43
        return "Appoint %s" % self.driver_title
44
45
    @property
46
    def driver_title(self):
47
        """The title of the driver."""
48
        if IProductSeries.providedBy(self.context):
49
            return "release manager"
50
        else:
51
            return 'driver'
52
53
    @property
54
    def page_title(self):
55
        return 'Appoint the %s for %s' % (
56
            self.driver_title, self.context.title)
57
3691.401.1 by Diogo Matsubara
Fixes bug 62423 (The 'appoint driver' form is broken for projects), adds a common AppointDriverView that will be used by all +driver pages
58
    @action('Change', name='change')
59
    def change_action(self, action, data):
8566.2.1 by Curtis Hovey
Use the term 'Release manager' to distinguish the series driver from the project drivers.
60
        """Change the driver."""
3691.401.1 by Diogo Matsubara
Fixes bug 62423 (The 'appoint driver' form is broken for projects), adds a common AppointDriverView that will be used by all +driver pages
61
        driver = data['driver']
62
        self.updateContextFromData(data)
63
        if driver:
64
            self.request.response.addNotification(
8566.2.1 by Curtis Hovey
Use the term 'Release manager' to distinguish the series driver from the project drivers.
65
                "Successfully changed the %s to %s" % (
66
                    self.driver_title, driver.displayname))
3691.401.1 by Diogo Matsubara
Fixes bug 62423 (The 'appoint driver' form is broken for projects), adds a common AppointDriverView that will be used by all +driver pages
67
        else:
68
            self.request.response.addNotification(
8566.2.1 by Curtis Hovey
Use the term 'Release manager' to distinguish the series driver from the project drivers.
69
                "Successfully removed the %s" % self.driver_title)
3691.401.1 by Diogo Matsubara
Fixes bug 62423 (The 'appoint driver' form is broken for projects), adds a common AppointDriverView that will be used by all +driver pages
70
71
    @property
72
    def next_url(self):
8566.2.1 by Curtis Hovey
Use the term 'Release manager' to distinguish the series driver from the project drivers.
73
        """See `LaunchpadFormView`."""
74
        return canonical_url(self.context)
75
76
    @property
77
    def cancel_url(self):
78
        """See `LaunchpadFormView`."""
3691.401.1 by Diogo Matsubara
Fixes bug 62423 (The 'appoint driver' form is broken for projects), adds a common AppointDriverView that will be used by all +driver pages
79
        return canonical_url(self.context)