~launchpad-pqm/launchpad/devel

8687.15.11 by Karl Fogel
Add the copyright header block to files under lib/lp/answers/.
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4319.2.22 by Francis J. Lacoste
Add IStructuralObjectPresentaiton adapter for IFAQ.
3
4319.5.5 by Francis J. Lacoste
Typos and style.
4
"""`IFAQ` browser views."""
4319.2.22 by Francis J. Lacoste
Add IStructuralObjectPresentaiton adapter for IFAQ.
5
6
__metaclass__ = type
7
8
__all__ = [
9826.4.1 by Curtis Hovey
Added FAQ Breadcrumb adapter to fix crumbs and title. Fixed the heading.
9
    'FAQBreadcrumb',
9098.7.5 by Paul Hummer
Fixed faq-index.pt
10
    'FAQNavigationMenu',
4319.2.50 by Francis J. Lacoste
Add +edit view on IFAQ.
11
    'FAQEditView',
9517.4.6 by Paul Hummer
Fixed FAQ titles
12
    'FAQView',
4319.2.22 by Francis J. Lacoste
Add IStructuralObjectPresentaiton adapter for IFAQ.
13
    ]
14
15
from canonical.launchpad import _
9098.7.5 by Paul Hummer
Fixed faq-index.pt
16
from canonical.launchpad.webapp import (
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
17
    action,
18
    canonical_url,
19
    enabled_with_permission,
20
    LaunchpadEditFormView,
21
    LaunchpadView,
22
    Link,
23
    NavigationMenu,
24
    )
9826.4.1 by Curtis Hovey
Added FAQ Breadcrumb adapter to fix crumbs and title. Fixed the heading.
25
from canonical.launchpad.webapp.breadcrumb import Breadcrumb
7944.3.18 by Francis J. Lacoste
Rename lp.apps.answers to lp.answers.
26
from lp.answers.browser.faqcollection import FAQCollectionMenu
9098.7.5 by Paul Hummer
Fixed faq-index.pt
27
from lp.answers.interfaces.faq import IFAQ
9098.7.8 by Paul Hummer
Fixed test failures
28
from lp.answers.interfaces.faqcollection import IFAQCollection
9098.7.5 by Paul Hummer
Fixed faq-index.pt
29
30
31
class FAQNavigationMenu(NavigationMenu):
4319.2.51 by Francis J. Lacoste
Typos.
32
    """Context menu of actions that can be performed upon a FAQ."""
9098.7.5 by Paul Hummer
Fixed faq-index.pt
33
4319.2.50 by Francis J. Lacoste
Add +edit view on IFAQ.
34
    usedfor = IFAQ
9098.7.5 by Paul Hummer
Fixed faq-index.pt
35
    title = 'Edit FAQ'
36
    facet = 'answers'
9098.7.7 by Paul Hummer
Added list_all link
37
    links = ['edit', 'list_all']
4319.2.50 by Francis J. Lacoste
Add +edit view on IFAQ.
38
39
    @enabled_with_permission('launchpad.Edit')
40
    def edit(self):
41
        """Return a Link to the edit view."""
9098.7.5 by Paul Hummer
Fixed faq-index.pt
42
        return Link('+edit', _('Edit FAQ'), icon='edit')
4319.2.50 by Francis J. Lacoste
Add +edit view on IFAQ.
43
9098.7.7 by Paul Hummer
Added list_all link
44
    def list_all(self):
45
        """Return a Link to list all FAQs."""
46
        # We adapt to IFAQCollection so that the link can be used
47
        # on objects which don't provide `IFAQCollection` directly, but for
48
        # which an adapter exists that gives the proper context.
49
        collection = IFAQCollection(self.context)
50
        url = canonical_url(collection, rootsite='answers') + '/+faqs'
51
        return Link(url, 'List all FAQs', icon='info')
52
4319.2.50 by Francis J. Lacoste
Add +edit view on IFAQ.
53
9826.4.1 by Curtis Hovey
Added FAQ Breadcrumb adapter to fix crumbs and title. Fixed the heading.
54
class FAQBreadcrumb(Breadcrumb):
55
    """Builds a breadcrumb for an `IFAQ`."""
56
57
    @property
58
    def text(self):
59
        return 'FAQ #%d' % self.context.id
60
61
9517.4.6 by Paul Hummer
Fixed FAQ titles
62
class FAQView(LaunchpadView):
63
    """View for the FAQ index."""
64
65
    @property
9826.4.1 by Curtis Hovey
Added FAQ Breadcrumb adapter to fix crumbs and title. Fixed the heading.
66
    def label(self):
67
        return self.context.title
9517.4.6 by Paul Hummer
Fixed FAQ titles
68
69
4319.2.50 by Francis J. Lacoste
Add +edit view on IFAQ.
70
class FAQEditView(LaunchpadEditFormView):
4319.2.51 by Francis J. Lacoste
Typos.
71
    """View to change the FAQ details."""
4319.2.50 by Francis J. Lacoste
Add +edit view on IFAQ.
72
73
    schema = IFAQ
74
    label = _('Edit FAQ')
75
    field_names = ["title", "keywords", "content"]
76
9098.5.18 by Paul Hummer
Fixed the missing page title for faq-edit.pt
77
    @property
78
    def page_title(self):
79
        return 'Edit FAQ #%s details' % self.context.id
80
4319.2.50 by Francis J. Lacoste
Add +edit view on IFAQ.
81
    @action(_('Save'), name="save")
82
    def save_action(self, action, data):
83
        """Update the FAQ details."""
84
        self.updateContextFromData(data)
85
        self.next_url = canonical_url(self.context)