# HG changeset patch # User Thierry Florac # Date 1507876494 -7200 # Node ID fa51a3ae17a14c91f30f407c206af3b5721003b6 # Parent f9744fecbb237dce5875c612e562019f663f39d9 Updated preview management diff -r f9744fecbb23 -r fa51a3ae17a1 src/pyams_content/component/paragraph/zmi/preview.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_content/component/paragraph/zmi/preview.py Fri Oct 13 08:34:54 2017 +0200 @@ -0,0 +1,50 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces +from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \ + IParagraphSummary +from pyams_content.shared.common.interfaces.zmi import IPreviewForm +from pyams_form.interfaces.form import IWidgetsSuffixViewletsManager +from pyams_i18n.interfaces import II18nManager +from pyams_skin.layer import IPyAMSLayer + +# import packages +from pyams_template.template import template_config +from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION +from pyams_viewlet.viewlet import viewlet_config, Viewlet + + +@viewlet_config(name='paragraphs-preview', context=IParagraphContainerTarget, layer=IPyAMSLayer, + view=IPreviewForm, manager=IWidgetsSuffixViewletsManager, + permission=VIEW_SYSTEM_PERMISSION, weight=100) +@template_config(template='templates/preview.pt', layer=IPyAMSLayer) +class ParagraphsContainerPreview(Viewlet): + """Paragraphs container preview""" + + def __init__(self, context, request, view, manager): + super(ParagraphsContainerPreview, self).__init__(context, request, view, manager) + self.paragraphs = [para for para in IParagraphContainer(self.context).values() + if para.visible] + self.languages = II18nManager(self.context).get_languages() + + def render_paragraph(self, paragraph, language=None): + renderer = self.request.registry.queryMultiAdapter((paragraph, self.request), IParagraphSummary) + if renderer is not None: + renderer.language = language + renderer.update() + return renderer.render() diff -r f9744fecbb23 -r fa51a3ae17a1 src/pyams_content/component/paragraph/zmi/summary.py --- a/src/pyams_content/component/paragraph/zmi/summary.py Fri Oct 13 08:33:53 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -# -# Copyright (c) 2008-2015 Thierry Florac -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED -# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE. -# - -__docformat__ = 'restructuredtext' - - -# import standard library - -# import interfaces -from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \ - IParagraphSummary -from pyams_content.shared.common.interfaces.zmi import IInnerSummaryView -from pyams_form.interfaces.form import IInnerTabForm -from pyams_i18n.interfaces import II18nManager -from pyams_skin.layer import IPyAMSLayer - -# import packages -from pyams_content.shared.common.zmi.summary import SharedContentSummaryForm -from pyams_pagelet.pagelet import pagelet_config -from pyams_template.template import template_config -from pyams_utils.adapter import adapter_config -from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION -from pyams_zmi.form import InnerAdminDisplayForm -from z3c.form import field -from zope.interface import implementer, Interface - -from pyams_content import _ - - -@adapter_config(name='paragraphs-summary', - context=(IParagraphContainerTarget, IPyAMSLayer, SharedContentSummaryForm), - provides=IInnerTabForm) -class ParagraphsContainerSummaryForm(InnerAdminDisplayForm): - """Paragraphs container summary""" - - weight = 20 - tab_label = _("Quick preview") - tab_target = 'paragraphs-summary.html' - - fields = field.Fields(Interface) - - -@pagelet_config(name='paragraphs-summary.html', context=IParagraphContainerTarget, layer=IPyAMSLayer, - permission=VIEW_SYSTEM_PERMISSION) -@template_config(template='templates/summary.pt', layer=IPyAMSLayer) -@implementer(IInnerSummaryView) -class ParagraphsContainerSummaryView(object): - """Paragraphs container summary view""" - - def __init__(self, context, request): - super(ParagraphsContainerSummaryView, self).__init__(context, request) - self.paragraphs = [para for para in IParagraphContainer(self.context).values() - if para.visible] - self.languages = II18nManager(self.context).get_languages() - - def render_paragraph(self, paragraph, language=None): - renderer = self.request.registry.queryMultiAdapter((paragraph, self.request), IParagraphSummary) - if renderer is not None: - renderer.language = language - renderer.update() - return renderer.render() diff -r f9744fecbb23 -r fa51a3ae17a1 src/pyams_content/component/paragraph/zmi/templates/preview.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_content/component/paragraph/zmi/templates/preview.pt Fri Oct 13 08:34:54 2017 +0200 @@ -0,0 +1,35 @@ + + +
+ +

This content doesn't contain any paragraph.

+
+
+ + +
+ +
+ +

This content doesn't contain any paragraph.

+
+
+
+
+
diff -r f9744fecbb23 -r fa51a3ae17a1 src/pyams_content/component/paragraph/zmi/templates/summary.pt --- a/src/pyams_content/component/paragraph/zmi/templates/summary.pt Fri Oct 13 08:33:53 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ - - -
- -

This content doesn't contain any paragraph.

-
-
- - -
- -
- -

This content doesn't contain any paragraph.

-
-
-
-
-