# HG changeset patch # User Thierry Florac # Date 1530174939 -7200 # Node ID 62c109c762ce2d75309c2fcf0bd627153910da6a # Parent 0d5b5c156baaca763e63e2c0da0823572ad32f56 Updated image rendering function diff -r 0d5b5c156baa -r 62c109c762ce 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 = ''.format(url) if css_class: result = '
{1}
'.format(css_class, result)