Updated image rendering function
authorThierry Florac <thierry.florac@onf.fr>
Thu, 28 Jun 2018 10:35:39 +0200
changeset 109 62c109c762ce
parent 108 0d5b5c156baa
child 110 dc5015906061
Updated image rendering function
src/pyams_file/zmi/image.py
--- a/src/pyams_file/zmi/image.py	Thu Jun 28 08:36:49 2018 +0200
+++ b/src/pyams_file/zmi/image.py	Thu Jun 28 10:35:39 2018 +0200
@@ -9,7 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from transaction.interfaces import ITransactionManager
 
 __docformat__ = 'restructuredtext'
 
@@ -30,6 +29,7 @@
 from pyams_skin.layer import IPyAMSLayer
 from pyams_utils.interfaces import VIEW_PERMISSION, ICacheKeyValue
 from pyams_zmi.layer import IAdminLayer
+from transaction.interfaces import ITransactionManager
 from zope.dublincore.interfaces import IZopeDublinCore
 
 # import packages
@@ -42,6 +42,7 @@
 from pyams_skin.viewlet.toolbar import ToolbarActionItem
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
+from pyams_utils.request import check_request
 from pyams_utils.url import absolute_url
 from pyams_viewlet.viewlet import viewlet_config, Viewlet
 from pyams_zmi.form import AdminDialogEditForm
@@ -71,16 +72,23 @@
 
 def render_img(image, width=None, height=None, request=None, css_class='', timestamp=False):
     """Render image thumbnail"""
+    thumbnail = None
     thumbnails = IThumbnail(image, None)
     if thumbnails is not None:
         if width or height:
             thumbnail = thumbnails.get_thumbnail('{0}x{1}'.format(width, height))
     if thumbnail is None:
         thumbnail = image
+    if request is None:
+        request = check_request()
     url = absolute_url(thumbnail, request)
     if timestamp:
-        timestamp = random.randint(0, sys.maxsize)
-        url += '?_={1}'.format(timestamp)
+        dc = IZopeDublinCore(thumbnail, None)
+        if dc is None:
+            timestamp = random.randint(0, sys.maxsize)
+        else:
+            timestamp = dc.modified.timestamp()
+        url += '?_={0}'.format(timestamp)
     result = '<img src="{0}" />'.format(url)
     if css_class:
         result = '<div class="{0}">{1}</div>'.format(css_class, result)