Added argument to "picture" TALES expression
authorThierry Florac <tflorac@ulthar.net>
Tue, 04 May 2021 12:38:32 +0200
changeset 218 458cf3d033aa
parent 217 48a990f311cb
child 219 1c07e0c889ba
Added argument to "picture" TALES expression
src/pyams_file/skin/__init__.py
src/pyams_file/skin/templates/picture.pt
src/pyams_file/skin/templates/svg-picture.pt
--- a/src/pyams_file/skin/__init__.py	Tue Jan 12 13:35:20 2021 +0100
+++ b/src/pyams_file/skin/__init__.py	Tue May 04 12:38:32 2021 +0200
@@ -35,36 +35,38 @@
 
     def render(self, context=None, lg_thumb='lg', lg_width=12, md_thumb='md', md_width=12,
                sm_thumb='sm', sm_width=12, xs_thumb='xs', xs_width=12,
-               def_thumb=None, def_width=None, alt='', css_class=''):
+               def_thumb=None, def_width=None, alt='', css_class='', img_width='100%'):
         if context is None:
             context = self.context
         if context.content_type.startswith('image/svg'):
-            return render('templates/svg-picture.pt',
-                          {'image': context,
-                           'lg_width': lg_width,
-                           'md_width': md_width,
-                           'sm_width': sm_width,
-                           'xs_width': xs_width,
-                           'alt': alt,
-                           'css_class': css_class},
-                          request=self.request)
+            return render('templates/svg-picture.pt', {
+                'image': context,
+                'lg_width': lg_width,
+                'md_width': md_width,
+                'sm_width': sm_width,
+                'xs_width': xs_width,
+                'alt': alt,
+                'css_class': css_class,
+                'img_width': img_width
+            }, request=self.request)
         else:
             if def_thumb is None:
                 def_thumb = md_thumb or lg_thumb or sm_thumb or xs_thumb
             if def_width is None:
                 def_width = md_width or lg_width or sm_width or xs_width
-            return render('templates/picture.pt',
-                          {'image': context,
-                           'lg_thumb': lg_thumb,
-                           'lg_width': lg_width,
-                           'md_thumb': md_thumb,
-                           'md_width': md_width,
-                           'sm_thumb': sm_thumb,
-                           'sm_width': sm_width,
-                           'xs_thumb': xs_thumb,
-                           'xs_width': xs_width,
-                           'def_thumb': def_thumb,
-                           'def_width': def_width,
-                           'alt': alt,
-                           'css_class': css_class},
-                          request=self.request)
\ No newline at end of file
+            return render('templates/picture.pt', {
+                'image': context,
+                'lg_thumb': lg_thumb,
+                'lg_width': lg_width,
+                'md_thumb': md_thumb,
+                'md_width': md_width,
+                'sm_thumb': sm_thumb,
+                'sm_width': sm_width,
+                'xs_thumb': xs_thumb,
+                'xs_width': xs_width,
+                'def_thumb': def_thumb,
+                'def_width': def_width,
+                'alt': alt,
+                'css_class': css_class,
+                'img_width': img_width
+            }, request=self.request)
--- a/src/pyams_file/skin/templates/picture.pt	Tue Jan 12 13:35:20 2021 +0100
+++ b/src/pyams_file/skin/templates/picture.pt	Tue May 04 12:38:32 2021 +0200
@@ -46,7 +46,7 @@
 			srcset="/--static--/myams/img/dot.png" />
 	<tal:if condition="def_width">
 		<!-- fallback image -->
-		<img style="width: 100%;" class="${css_class}"
+		<img style="width: ${img_width};" class="${css_class}"
 			 tal:define="width str(round(1200 / 12 * def_width));
 						 thumb thumbnails.get_thumbnail(def_thumb + ':w' + width);
 						 timestamp tales:timestamp(thumb);"
--- a/src/pyams_file/skin/templates/svg-picture.pt	Tue Jan 12 13:35:20 2021 +0100
+++ b/src/pyams_file/skin/templates/svg-picture.pt	Tue May 04 12:38:32 2021 +0200
@@ -14,7 +14,7 @@
 			media="(min-width: 1200px)"
 			srcset="/--static--/myams/img/dot.png" />
 	<!-- fallback image -->
-	<img style="width: 100%;"
+	<img style="width: ${img_width};"
 		 tal:define="timestamp tales:timestamp(image)"
 		 alt="${alt}" src="${image_url}?_=${timestamp}" />
 </picture>