Updated preview management
authorThierry Florac <thierry.florac@onf.fr>
Fri, 13 Oct 2017 08:34:54 +0200
changeset 219 fa51a3ae17a1
parent 218 f9744fecbb23
child 220 82ba8b3e99f3
Updated preview management
src/pyams_content/component/paragraph/zmi/preview.py
src/pyams_content/component/paragraph/zmi/summary.py
src/pyams_content/component/paragraph/zmi/templates/preview.pt
src/pyams_content/component/paragraph/zmi/templates/summary.pt
--- /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 <tflorac AT ulthar.net>
+# 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()
--- 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 <tflorac AT ulthar.net>
-# 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()
--- /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 @@
+<tal:var define="langs view.languages" i18n:domain="pyams_content">
+	<tal:if condition="len(langs) == 1">
+		<div class="margin-top-10">
+			<tal:loop repeat="paragraph view.paragraphs"
+					  replace="structure view.render_paragraph(paragraph)" />
+			<p tal:condition="not:view.paragraphs"
+			   i18n:translate="">This content doesn't contain any paragraph.</p>
+		</div>
+	</tal:if>
+	<tal:if condition="len(langs) > 1">
+		<ul class="nav nav-tabs margin-top-10">
+			<tal:loop repeat="lang langs">
+				<li tal:define="active python:'active' if repeat['lang'].start() else ''"
+					tal:attributes="class string:small ${active}">
+					<a data-toggle="tab" class="xsmall"
+					   tal:attributes="href string:#paragraphs-${lang}">
+						<img tal:attributes="src string:/--static--/pyams_i18n/img/flags/${lang}.png" />
+					</a>
+				</li>
+			</tal:loop>
+		</ul>
+		<div class="tab-content i18n-content bordered nohover">
+			<tal:loop repeat="lang langs">
+				<div tal:define="active python:'active' if repeat['lang'].start() else ''"
+					 tal:attributes="class string:clearfix tab-pane ${active} fade in padding-5;
+									 id string:paragraphs-${lang};">
+					<tal:loop repeat="paragraph view.paragraphs"
+							  replace="structure view.render_paragraph(paragraph, lang)" />
+					<p tal:condition="not:view.paragraphs"
+					   i18n:translate="">This content doesn't contain any paragraph.</p>
+				</div>
+			</tal:loop>
+		</div>
+	</tal:if>
+</tal:var>
--- 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 @@
-<tal:var define="langs view.languages" i18n:domain="pyams_content">
-	<tal:if condition="len(langs) == 1">
-		<div class="margin-top-10">
-			<tal:loop repeat="paragraph view.paragraphs"
-					  replace="structure view.render_paragraph(paragraph)" />
-			<p tal:condition="not:view.paragraphs"
-			   i18n:translate="">This content doesn't contain any paragraph.</p>
-		</div>
-	</tal:if>
-	<tal:if condition="len(langs) > 1">
-		<ul class="nav nav-tabs margin-top-10">
-			<tal:loop repeat="lang langs">
-				<li tal:define="active python:'active' if repeat['lang'].start() else ''"
-					tal:attributes="class string:small ${active}">
-					<a data-toggle="tab" class="xsmall"
-					   tal:attributes="href string:#paragraphs-${lang}">
-						<img tal:attributes="src string:/--static--/pyams_i18n/img/flags/${lang}.png" />
-					</a>
-				</li>
-			</tal:loop>
-		</ul>
-		<div class="tab-content i18n-content bordered nohover">
-			<tal:loop repeat="lang langs">
-				<div tal:define="active python:'active' if repeat['lang'].start() else ''"
-					 tal:attributes="class string:clearfix tab-pane ${active} fade in padding-5;
-									 id string:paragraphs-${lang};">
-					<tal:loop repeat="paragraph view.paragraphs"
-							  replace="structure view.render_paragraph(paragraph, lang)" />
-					<p tal:condition="not:view.paragraphs"
-					   i18n:translate="">This content doesn't contain any paragraph.</p>
-				</div>
-			</tal:loop>
-		</div>
-	</tal:if>
-</tal:var>