Add default renderer to image map paragraph
authorThierry Florac <thierry.florac@onf.fr>
Fri, 25 May 2018 08:06:38 +0200
changeset 32 f0b28eb0bdf0
parent 31 566d98116bf2
child 33 c8d86f2bd778
Add default renderer to image map paragraph
src/pyams_default_theme/shared/imagemap/__init__.py
src/pyams_default_theme/shared/imagemap/templates/imagemap-default.pt
src/pyams_default_theme/shared/imagemap/templates/paragraph-render.pt
--- a/src/pyams_default_theme/shared/imagemap/__init__.py	Fri May 25 08:06:07 2018 +0200
+++ b/src/pyams_default_theme/shared/imagemap/__init__.py	Fri May 25 08:06:38 2018 +0200
@@ -17,17 +17,16 @@
 
 # import interfaces
 from pyams_content.component.association.interfaces import IAssociationInfo
-from pyams_content.component.paragraph.interfaces import IParagraphRenderer
 from pyams_content.features.renderer.interfaces import IContentRenderer
 from pyams_content.shared.imagemap.interfaces import IWfImageMap, IImageMapParagraph
-from pyams_i18n.interfaces import II18n
 from pyams_skin.layer import IPyAMSLayer
 
 # import packages
 from pyams_content.features.renderer.skin import BaseContentRenderer
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
-from pyams_viewlet.viewlet import BaseContentProvider
+
+from pyams_default_theme import _
 
 
 #
@@ -49,19 +48,14 @@
 # Imagemap paragraph renderer
 #
 
-@adapter_config(context=(IImageMapParagraph, IPyAMSLayer), provides=IParagraphRenderer)
-@template_config(template='templates/paragraph-render.pt', layer=IPyAMSLayer)
-class ImagemapParagraphRenderer(BaseContentProvider):
-    """Image map paragraph renderer"""
-
-    language = None
+@adapter_config(name='default', context=(IImageMapParagraph, IPyAMSLayer), provides=IContentRenderer)
+@template_config(template='templates/imagemap-default.pt', layer=IPyAMSLayer)
+class ImagemapDefaultParagraphRenderer(BaseContentRenderer):
+    """Image map default paragraph renderer"""
 
-    def update(self):
-        i18n = II18n(self.context)
-        if self.language:
-            setattr(self, 'title', i18n.get_attribute('title', self.language, request=self.request))
-        else:
-            setattr(self, 'title', i18n.query_attribute('title', request=self.request))
+    label = _("Default imagemap renderer")
+
+    i18n_context_attrs = ('title', )
 
     def get_item_info(self, item):
         return IAssociationInfo(item, None)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/imagemap/templates/imagemap-default.pt	Fri May 25 08:06:38 2018 +0200
@@ -0,0 +1,27 @@
+<h3 tal:content="view.title">title</h3>
+<div class="no-padding" i18n:domain="pyams_content"
+	 data-ams-plugins="pyams_content"
+	 tal:define="imagemap context.get_target()"
+	 tal:attributes="data-ams-plugin-pyams_content-src extension:resource_path('pyams_content.skin:pyams_content')">
+	<img usemap="#imagemap_preview"
+		 tal:define="image i18n:imagemap.image"
+		 tal:attributes="src extension:absolute_url(image);
+						 usemap string:#imagemap_preview_${context.__name__}"
+		 data-ams-callback="PyAMS_content.imgmap.initPreview" />
+	<map name="imagemap_preview"
+		 tal:attributes="name string:imagemap_preview_${context.__name__}">
+		<tal:loop repeat="area imagemap.areas.values()">
+			<tal:var define="item imagemap.get_association(area)"
+					 condition="item and item.visible">
+				<area shape="poly"
+					  tal:define="info view.get_item_info(item);
+								  area_title i18n:area.title;
+								  item_title i18n:info.user_title;
+								  title area_title or item_title;"
+					  tal:attributes="coords area.area;
+									  href item.get_url(request);
+									  title title;" />
+			</tal:var>
+		</tal:loop>
+	</map>
+</div>
--- a/src/pyams_default_theme/shared/imagemap/templates/paragraph-render.pt	Fri May 25 08:06:07 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-<h3 tal:content="view.title">title</h3>
-<div class="no-padding" i18n:domain="pyams_content"
-	 data-ams-plugins="pyams_content"
-	 tal:define="imagemap context.get_target()"
-	 tal:attributes="data-ams-plugin-pyams_content-src extension:resource_path('pyams_content.skin:pyams_content')">
-	<img usemap="#imagemap_preview"
-		 tal:define="image i18n:imagemap.image"
-		 tal:attributes="src extension:absolute_url(image);
-						 usemap string:#imagemap_preview_${context.__name__}"
-		 data-ams-callback="PyAMS_content.imgmap.initPreview" />
-	<map name="imagemap_preview"
-		 tal:attributes="name string:imagemap_preview_${context.__name__}">
-		<tal:loop repeat="area imagemap.areas.values()">
-			<tal:var define="item imagemap.get_association(area)"
-					 condition="item and item.visible">
-				<area shape="poly"
-					  tal:define="info view.get_item_info(item);
-								  area_title i18n:area.title;
-								  item_title i18n:info.user_title;
-								  title area_title or item_title;"
-					  tal:attributes="coords area.area;
-									  href item.get_url(request);
-									  title title;" />
-			</tal:var>
-		</tal:loop>
-	</map>
-</div>