Added thumbnail refresh of media thumbnail after save
authorThierry Florac <thierry.florac@onf.fr>
Tue, 10 Jul 2018 14:10:19 +0200
changeset 823 46d1f7b3d3bb
parent 822 5ac0fcedd89e
child 824 5a56ac57d94e
Added thumbnail refresh of media thumbnail after save
src/pyams_content/component/gallery/zmi/file.py
src/pyams_content/component/gallery/zmi/templates/gallery-media-thumbnail.pt
src/pyams_content/component/gallery/zmi/templates/gallery-medias.pt
--- a/src/pyams_content/component/gallery/zmi/file.py	Tue Jul 10 13:35:28 2018 +0200
+++ b/src/pyams_content/component/gallery/zmi/file.py	Tue Jul 10 14:10:19 2018 +0200
@@ -9,6 +9,10 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
+from pyramid.renderers import render
+from zope.dublincore.interfaces import IZopeDublinCore
+
+from pyams_skin.event import get_json_refresh_event
 
 __docformat__ = 'restructuredtext'
 
@@ -16,7 +20,7 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.gallery.interfaces import IGallery, IGalleryFile
+from pyams_content.component.gallery.interfaces import IGallery, IGalleryFile, IGalleryParagraph
 from pyams_content.component.gallery.zmi.interfaces import IGalleryMediasAddFields, IGalleryContentsView
 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
 from pyams_file.interfaces.archive import IArchiveExtractor
@@ -227,6 +231,12 @@
                         'title': II18n(self.context).query_attribute('title', request=self.request)
                     }
                 })
+        paragraph = get_parent(self.context, IGalleryParagraph)
+        if paragraph is not None:
+            output.setdefault('events', []).append(
+                get_json_refresh_event(object_id='media_{0}_{1}'.format(paragraph.__name__, self.context.__name__),
+                                       content=render('templates/gallery-media-thumbnail.pt',
+                                                      {'media': self.context}, request=self.request)))
         return output
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/gallery/zmi/templates/gallery-media-thumbnail.pt	Tue Jul 10 14:10:19 2018 +0200
@@ -0,0 +1,13 @@
+<img class="thumbnail"
+	 data-ams-hint-gravity="s"
+	 tal:define="thumbnails tales:thumbnails(media.data);
+				 thumbnail thumbnails.get_thumbnail('128x128');
+				 image_size thumbnail.get_image_size();
+				 margin_left 64 - image_size[0] / 2;
+				 margin_top 64 - image_size[1] / 2;
+				 title i18n:media.title;
+				 src tales:absolute_url(thumbnail);"
+	 tal:attributes="src string:${src}?_=${tales:timestamp(thumbnail)};
+					 id 'media_{0}_{1}'.format(context.__name__, media.__name__);
+					 original-title title or '--';
+					 style string:margin-left: ${margin_left}px;; margin-right: ${margin_left}px;; margin-top: ${margin_top}px;; margin-bottom: ${margin_top}px;;" />
--- a/src/pyams_content/component/gallery/zmi/templates/gallery-medias.pt	Tue Jul 10 13:35:28 2018 +0200
+++ b/src/pyams_content/component/gallery/zmi/templates/gallery-medias.pt	Tue Jul 10 14:10:19 2018 +0200
@@ -49,8 +49,9 @@
 												 image_size thumbnail.get_image_size();
 												 margin_left 64 - image_size[0] / 2;
 												 margin_top 64 - image_size[1] / 2;
-												 title i18n:media.title;"
-									 tal:attributes="src tales:absolute_url(thumbnail);
+												 title i18n:media.title;
+												 src tales:absolute_url(thumbnail);"
+									 tal:attributes="src string:${src}?_=${tales:timestamp(thumbnail)};
 													 id 'media_{0}_{1}'.format(context.__name__, media.__name__);
 													 original-title title or '--';
 													 style string:margin-left: ${margin_left}px;; margin-right: ${margin_left}px;; margin-top: ${margin_top}px;; margin-bottom: ${margin_top}px;;" />