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
|
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""`IFAQ` browser views."""
__metaclass__ = type
__all__ = [
'FAQBreadcrumb',
'FAQNavigationMenu',
'FAQEditView',
'FAQView',
]
from canonical.launchpad import _
from canonical.launchpad.webapp import (
action,
canonical_url,
enabled_with_permission,
LaunchpadEditFormView,
LaunchpadView,
Link,
NavigationMenu,
)
from canonical.launchpad.webapp.breadcrumb import Breadcrumb
from lp.answers.browser.faqcollection import FAQCollectionMenu
from lp.answers.interfaces.faq import IFAQ
from lp.answers.interfaces.faqcollection import IFAQCollection
class FAQNavigationMenu(NavigationMenu):
"""Context menu of actions that can be performed upon a FAQ."""
usedfor = IFAQ
title = 'Edit FAQ'
facet = 'answers'
links = ['edit', 'list_all']
@enabled_with_permission('launchpad.Edit')
def edit(self):
"""Return a Link to the edit view."""
return Link('+edit', _('Edit FAQ'), icon='edit')
def list_all(self):
"""Return a Link to list all FAQs."""
# We adapt to IFAQCollection so that the link can be used
# on objects which don't provide `IFAQCollection` directly, but for
# which an adapter exists that gives the proper context.
collection = IFAQCollection(self.context)
url = canonical_url(collection, rootsite='answers') + '/+faqs'
return Link(url, 'List all FAQs', icon='info')
class FAQBreadcrumb(Breadcrumb):
"""Builds a breadcrumb for an `IFAQ`."""
@property
def text(self):
return 'FAQ #%d' % self.context.id
class FAQView(LaunchpadView):
"""View for the FAQ index."""
@property
def label(self):
return self.context.title
class FAQEditView(LaunchpadEditFormView):
"""View to change the FAQ details."""
schema = IFAQ
label = _('Edit FAQ')
field_names = ["title", "keywords", "content"]
@property
def page_title(self):
return 'Edit FAQ #%s details' % self.context.id
@action(_('Save'), name="save")
def save_action(self, action, data):
"""Update the FAQ details."""
self.updateContextFromData(data)
self.next_url = canonical_url(self.context)
|