Updated "thumbnail" TALES extension
authorThierry Florac <thierry.florac@onf.fr>
Mon, 15 Oct 2018 14:49:15 +0200
changeset 142 dff3e8842726
parent 141 c678b88b390b
child 143 fcecd9234dea
Updated "thumbnail" TALES extension
src/pyams_file/zmi/image.py
--- a/src/pyams_file/zmi/image.py	Fri Oct 12 08:27:14 2018 +0200
+++ b/src/pyams_file/zmi/image.py	Mon Oct 15 14:49:15 2018 +0200
@@ -20,20 +20,19 @@
 from pyramid.renderers import render
 from pyramid.view import view_config
 from transaction.interfaces import ITransactionManager
-from z3c.form import field, button
+from z3c.form import button, field
 from zope.dublincore.interfaces import IZopeDublinCore
-from zope.interface import implementer, Interface
-from zope.schema import Int, Bool
+from zope.interface import Interface, implementer
+from zope.schema import Bool, Int
 from zope.schema.fieldproperty import FieldProperty
 
-from pyams_file import _
 from pyams_file.image import ThumbnailGeometry
-from pyams_file.interfaces import IImage, IThumbnails, IResponsiveImage, IFileModifierForm, IThumbnailer, \
-    IFileInfo, IThumbnailForm, IMediaWidget, ISVGImage
+from pyams_file.interfaces import IFileInfo, IFileModifierForm, IImage, IMediaWidget, IResponsiveImage, ISVGImage, \
+    IThumbnailForm, IThumbnailer, IThumbnails
 from pyams_file.zmi import FileModifierAction
 from pyams_form.form import DialogDisplayForm, ajax_config
 from pyams_form.help import FormHelp
-from pyams_form.interfaces.form import IWidgetsPrefixViewletsManager, IFormHelp
+from pyams_form.interfaces.form import IFormHelp, IWidgetsPrefixViewletsManager
 from pyams_form.schema import CloseButton
 from pyams_i18n.interfaces import II18n
 from pyams_pagelet.pagelet import pagelet_config
@@ -43,13 +42,15 @@
 from pyams_skin.viewlet.toolbar import ToolbarActionItem
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
-from pyams_utils.interfaces import VIEW_PERMISSION, ICacheKeyValue
+from pyams_utils.interfaces import ICacheKeyValue, VIEW_PERMISSION
 from pyams_utils.request import check_request
 from pyams_utils.url import absolute_url
-from pyams_viewlet.viewlet import viewlet_config, Viewlet
+from pyams_viewlet.viewlet import Viewlet, viewlet_config
 from pyams_zmi.form import AdminDialogEditForm
 from pyams_zmi.layer import IAdminLayer
 
+from pyams_file import _
+
 
 #
 # SVG utilities
@@ -75,8 +76,12 @@
     thumbnail = None
     thumbnails = IThumbnails(image, None)
     if thumbnails is not None:
-        if width or height:
+        if width and height:
             thumbnail = thumbnails.get_thumbnail('{0}x{1}'.format(width, height))
+        elif width and (width != 'auto'):
+            thumbnail = thumbnails.get_thumbnail('w{0}'.format(width))
+        elif height and (height != 'auto'):
+            thumbnail = thumbnails.get_thumbnail('h{0}'.format(height))
     if thumbnail is None:
         thumbnail = image
     if request is None: