src/pyams_content/component/illustration/zmi/__init__.py
changeset 395 2a39b333a585
parent 360 e47b68b41f06
child 489 dcdb0ce828f8
--- a/src/pyams_content/component/illustration/zmi/__init__.py	Sun Feb 11 12:11:05 2018 +0100
+++ b/src/pyams_content/component/illustration/zmi/__init__.py	Thu Feb 15 15:08:29 2018 +0100
@@ -16,10 +16,9 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.illustration.interfaces import IIllustration, IIllustrationRenderer, IIllustrationTarget
+from pyams_content.component.illustration.interfaces import IIllustration, IIllustrationTarget
 from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerTable, IParagraphTitleToolbar
 from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager
-from pyams_i18n.interfaces import II18n
 from pyams_skin.layer import IPyAMSLayer
 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
 from pyams_utils.interfaces.data import IObjectData
@@ -27,11 +26,12 @@
 from transaction.interfaces import ITransactionManager
 
 # import packages
+from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
 from pyams_content.skin import pyams_content
 from pyams_form.security import ProtectedFormObjectMixin
 from pyams_skin.viewlet.toolbar import JsToolbarAction
-from pyams_template.template import get_view_template, template_config
-from pyams_utils.adapter import ContextRequestAdapter, adapter_config
+from pyams_template.template import template_config
+from pyams_utils.adapter import adapter_config
 from pyams_utils.fanstatic import get_resource_path
 from pyams_viewlet.viewlet import viewlet_config, Viewlet
 from pyams_zmi.form import InnerAdminEditForm
@@ -42,63 +42,6 @@
 
 
 #
-# Illustration renderers
-#
-
-class BaseIllustrationRenderer(ContextRequestAdapter):
-    """Base illustration renderer"""
-
-    language = None
-
-    def update(self):
-        i18n = II18n(self.context)
-        if self.language:
-            self.legend = i18n.get_attribute('alt_title', self.language, request=self.request)
-        else:
-            self.legend = i18n.query_attribute('alt_title', request=self.request)
-
-    render = get_view_template()
-
-
-@adapter_config(name='hidden', context=(IIllustration, IPyAMSLayer), provides=IIllustrationRenderer)
-class HiddenIllustrationRenderer(BaseIllustrationRenderer):
-    """Hidden illustration renderer"""
-
-    label = _("Hidden illustration")
-    weight = -999
-
-    def render(self):
-        return ''
-
-
-@adapter_config(name='default', context=(IIllustration, IPyAMSLayer), provides=IIllustrationRenderer)
-@template_config(template='templates/renderer-default.pt', layer=IPyAMSLayer)
-class DefaultIllustrationRenderer(BaseIllustrationRenderer):
-    """Default illustration renderer"""
-
-    label = _("Centered illustration")
-    weight = 1
-
-
-@adapter_config(name='left+zoom', context=(IIllustration, IPyAMSLayer), provides=IIllustrationRenderer)
-@template_config(template='templates/renderer-left.pt', layer=IPyAMSLayer)
-class LeftIllustrationWithZoomRenderer(BaseIllustrationRenderer):
-    """Illustrtaion renderer with small image and zoom"""
-
-    label = _("Small illustration on the left with zoom")
-    weight = 2
-
-
-@adapter_config(name='right+zoom', context=(IIllustration, IPyAMSLayer), provides=IIllustrationRenderer)
-@template_config(template='templates/renderer-right.pt', layer=IPyAMSLayer)
-class RightIllustrationWithZoomRenderer(BaseIllustrationRenderer):
-    """Illustrtaion renderer with small image and zoom"""
-
-    label = _("Small illustration on the right with zoom")
-    weight = 3
-
-
-#
 # Illustration properties inner edit form
 #
 
@@ -138,6 +81,8 @@
     legend_class = 'illustration switcher no-y-padding padding-right-10 pull-left width-auto'
 
     fields = field.Fields(IIllustration).omit('__parent__', '__name__')
+    fields['renderer'].widgetFactory = RendererFieldWidget
+
     hide_widgets_prefix_div = True
     weight = 10
 
@@ -155,7 +100,8 @@
 
     def get_ajax_output(self, changes):
         output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
-        if 'data' in changes.get(IIllustration, ()):
+        illustration_changes = changes.get(IIllustration, ())
+        if ('data' in illustration_changes) or ('renderer' in illustration_changes):
             # we have to commit transaction to be able to handle blobs...
             ITransactionManager(self.context).get().commit()
             form = IllustrationPropertiesInnerEditForm(self.context, self.request)