|
1 # |
|
2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net> |
|
3 # All Rights Reserved. |
|
4 # |
|
5 # This software is subject to the provisions of the Zope Public License, |
|
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
10 # FOR A PARTICULAR PURPOSE. |
|
11 # |
|
12 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \ |
|
13 IParagraphSummary |
|
14 from pyams_content.shared.common.interfaces.zmi import IInnerSummaryView |
|
15 from pyams_content.shared.common.zmi.summary import SharedContentSummaryForm |
|
16 from pyams_form.form import InnerDisplayForm |
|
17 from pyams_form.interfaces.form import IInnerTabForm |
|
18 from pyams_i18n.interfaces import II18nManager |
|
19 from pyams_pagelet.pagelet import pagelet_config |
|
20 from pyams_skin.layer import IPyAMSLayer |
|
21 from pyams_template.template import template_config |
|
22 from pyams_utils.adapter import adapter_config |
|
23 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION |
|
24 |
|
25 __docformat__ = 'restructuredtext' |
|
26 |
|
27 |
|
28 # import standard library |
|
29 |
|
30 # import interfaces |
|
31 |
|
32 # import packages |
|
33 from z3c.form import field |
|
34 from zope.interface import implementer, Interface |
|
35 |
|
36 from pyams_content import _ |
|
37 |
|
38 |
|
39 @adapter_config(name='paragraphs-summary', |
|
40 context=(IParagraphContainerTarget, IPyAMSLayer, SharedContentSummaryForm), |
|
41 provides=IInnerTabForm) |
|
42 class ParagraphsContainerSummary(InnerDisplayForm): |
|
43 """Paragraphs container summary""" |
|
44 |
|
45 weight = 20 |
|
46 tab_label = _("Paragraphs") |
|
47 tab_target = 'paragraphs-summary.html' |
|
48 |
|
49 fields = field.Fields(Interface) |
|
50 |
|
51 |
|
52 @pagelet_config(name='paragraphs-summary.html', context=IParagraphContainerTarget, layer=IPyAMSLayer, |
|
53 permission=VIEW_SYSTEM_PERMISSION) |
|
54 @template_config(template='templates/summary.pt', layer=IPyAMSLayer) |
|
55 @implementer(IInnerSummaryView) |
|
56 class ParagraphsContainerSummaryView(object): |
|
57 """Paragraphs container summary view""" |
|
58 |
|
59 def __init__(self, context, request): |
|
60 super(ParagraphsContainerSummaryView, self).__init__(context, request) |
|
61 self.paragraphs = IParagraphContainer(self.context) |
|
62 self.languages = II18nManager(self.context).get_languages() |
|
63 |
|
64 def render_paragraph(self, paragraph, language=None): |
|
65 renderer = self.request.registry.queryMultiAdapter((paragraph, self.request), IParagraphSummary) |
|
66 if renderer is not None: |
|
67 renderer.language = language |
|
68 renderer.update() |
|
69 return renderer.render() |