Updated banner viewlet
authorThierry Florac <thierry.florac@onf.fr>
Mon, 12 Nov 2018 11:39:49 +0100
changeset 214 03d87dee4723
parent 213 13da52c39ccc
child 215 78f7e033c9f4
Updated banner viewlet
src/pyams_default_theme/viewlet/banner/__init__.py
src/pyams_default_theme/viewlet/banner/templates/banner.pt
--- a/src/pyams_default_theme/viewlet/banner/__init__.py	Mon Nov 12 11:37:45 2018 +0100
+++ b/src/pyams_default_theme/viewlet/banner/__init__.py	Mon Nov 12 11:39:49 2018 +0100
@@ -12,19 +12,17 @@
 
 __docformat__ = 'restructuredtext'
 
+from pyramid.decorator import reify
+from zope.interface import Interface
 
-# import standard library
-
-# import interfaces
 from pyams_content.features.header.interfaces import IHeaderTarget, IHeaderSettings
 from pyams_default_theme.features.header.interfaces import ISimpleHeaderRendererSettings
+from pyams_default_theme.interfaces import IContentBannerIllustration
+from pyams_i18n.interfaces import II18n
 from pyams_skin.layer import IPyAMSUserLayer
-
-# import packages
 from pyams_template.template import template_config
 from pyams_utils.traversing import get_parent
 from pyams_viewlet.viewlet import contentprovider_config, ViewContentProvider
-from zope.interface import Interface
 
 
 @contentprovider_config(name='pyams.banner', layer=IPyAMSUserLayer, view=Interface)
@@ -32,10 +30,23 @@
 class Banner(ViewContentProvider):
     """Banner content provider"""
 
-    @property
+    @reify
     def settings(self):
         target = get_parent(self.context, IHeaderTarget)
         settings = IHeaderSettings(target)
         while settings.inherit:
             settings = IHeaderSettings(settings.parent)
         return ISimpleHeaderRendererSettings(settings.settings, None)
+
+    @property
+    def banner(self):
+        settings = self.settings
+        if settings is not None:
+            banner = settings.banner
+            if banner is not None:
+                return banner
+        registry = self.request.registry
+        illustration = registry.queryMultiAdapter((self.context, self.request),
+                                                  IContentBannerIllustration)
+        if illustration is not None:
+            return II18n(illustration).query_attribute('data', request=self.request)
--- a/src/pyams_default_theme/viewlet/banner/templates/banner.pt	Mon Nov 12 11:37:45 2018 +0100
+++ b/src/pyams_default_theme/viewlet/banner/templates/banner.pt	Mon Nov 12 11:39:49 2018 +0100
@@ -1,12 +1,14 @@
-<section class="wrapper-regularbanner" i18n:domain="onf_website"
-		 tal:define="settings view.settings"
-		 tal:condition="settings and settings.banner">
+<section class="wrapper-regularbanner" i18n:domain="onf_website">
 	<div class="regularbanner">
-		<div class="regularbanner__bg">
-			<img alt="" class="regularbanner__media"
-				 tal:define="image settings.banner"
-				 tal:attributes="src tales:absolute_url(image, '++thumb++w1320')" />
-		</div>  <!-- /.regularbanner__bg -->
+		<div class="regularbanner__bg"
+			tal:define="banner view.banner"
+			tal:condition="banner">
+			${structure:tales:picture(banner, lg_thumb='banner', md_thumb='banner',
+									  sm_thumb='banner', xs_thumb='banner', css_class='regularbanner__media')}
+			<!-- /.regularbanner__bg -->
+		</div>
 		<tal:var content="structure provider:pyams.logo" />
-	</div>  <!-- /.regularbanner -->
-</section>  <!-- /.wrapper-regularbanner -->
+		<!-- /.regularbanner -->
+	</div>
+	<!-- /.wrapper-regularbanner -->
+</section>