Updated image widget
authorThierry Florac <thierry.florac@onf.fr>
Wed, 17 Jan 2018 09:16:58 +0100
changeset 78 253f50a42c3d
parent 77 d22cb05c18f7
child 79 2ed1f847c318
Updated image widget
src/pyams_file/widget/__init__.py
src/pyams_file/widget/templates/image-display.pt
src/pyams_file/widget/templates/image-input.pt
--- a/src/pyams_file/widget/__init__.py	Sun Jan 14 12:49:15 2018 +0100
+++ b/src/pyams_file/widget/__init__.py	Wed Jan 17 09:16:58 2018 +0100
@@ -100,10 +100,10 @@
     def get_human_size(self, value):
         return get_human_size(value, self.request)
 
-    def get_thumbnail(self):
+    def get_thumbnail(self, geometry='128x128'):
         thumbnails = IThumbnail(self.current_value, None)
         if thumbnails is not None:
-            display = thumbnails.get_thumbnail('128x128')
+            display = thumbnails.get_thumbnail(geometry)
             if display is not None:
                 return '{0}?_={1}'.format(absolute_url(display, self.request), self.timestamp)
         name, ext = os.path.splitext(self.current_value.filename)
--- a/src/pyams_file/widget/templates/image-display.pt	Sun Jan 14 12:49:15 2018 +0100
+++ b/src/pyams_file/widget/templates/image-display.pt	Wed Jan 17 09:16:58 2018 +0100
@@ -11,24 +11,38 @@
 		   tal:attributes="href extension:absolute_url(target);"
 		   title="Zoom image" i18n:attributes="title">
 			<img class="thumbnail"
-				 tal:define="thumbnail python:thumbnails.get_thumbnail('128x128', 'jpeg');"
+				 tal:define="thumbnail python:thumbnails.get_thumbnail('128x128');"
 				 tal:attributes="src extension:absolute_url(thumbnail);
 								 title i18n:value.title;" title="" src="" alt="" />
 		</a>
-		<div class="margin-top-5">
-			<span i18n:translate="">Current value: </span>
-			<span tal:content="value/content_type"></span>
-			&nbsp;&ndash;&nbsp;
-			<span tal:content="python:'%d x %d' % value.get_image_size()"></span>
-			&nbsp;&ndash;&nbsp;
-			<span tal:content="python:view.get_human_size(value.get_size())"></span>
-			<br />
-			<a class="btn btn-xs btn-primary" target="download_window"
-			   tal:define="href extension:absolute_url(value)"
-			   tal:attributes="href string:${href}?download=1&_=${view/timestamp}"
-			   i18n:translate="">
-				Download
-			</a>
-		</div>
+		<tal:if condition="python:value.content_type.startswith('image/')">
+			<div class="margin-top-5">
+				<span i18n:translate="">Current value: </span>
+				<span tal:content="value/content_type"></span>
+				&nbsp;&ndash;&nbsp;
+				<span tal:content="python:'%d x %d' % value.get_image_size()"></span>
+				&nbsp;&ndash;&nbsp;
+				<span tal:content="python:view.get_human_size(value.get_size())"></span>
+				<br />
+				<a class="btn btn-xs btn-primary" target="download_window"
+				   tal:define="href extension:absolute_url(value)"
+				   tal:attributes="href string:${href}?download=1&_=${view/timestamp}"
+				   i18n:translate="">
+					Download
+				</a>
+			</div>
+		</tal:if>
+		<tal:if condition="not:python:value.content_type.startswith('image/')">
+			<div class="margin-top-5">
+				<span i18n:translate="">Current value: </span>
+				<span tal:content="value/content_type"></span>
+				&nbsp;&ndash;&nbsp;
+				<span tal:content="python:view.get_human_size(value.get_size())"></span>
+				<a class="btn btn-xs btn-primary" target="download_window"
+				   tal:define="href extension:absolute_url(value)"
+				   tal:attributes="href string:${href}?download=1&_=${view/timestamp}"
+				   i18n:translate="">Download</a>
+			</div>
+		</tal:if>
 	</div>
 </i18n:block>
--- a/src/pyams_file/widget/templates/image-input.pt	Sun Jan 14 12:49:15 2018 +0100
+++ b/src/pyams_file/widget/templates/image-input.pt	Wed Jan 17 09:16:58 2018 +0100
@@ -19,40 +19,71 @@
 				<span i18n:translate="">Delete content</span>
 			</label>
 		</div>
-		<a class="fancybox hint pull-left margin-5 margin-right-10" data-toggle
-		   data-ams-fancybox-type="image"
-		   data-ams-hint-gravity="e"
-		   data-ams-hint-offset="5"
-		   tal:define="thumbnails extension:thumbnails(value);
-					   target python:thumbnails.get_thumbnail('800x600', 'jpeg');"
-		   tal:attributes="href extension:absolute_url(target);"
-		   title="Zoom image" i18n:attributes="title">
-			<img class="thumbnail"
-				 tal:define="thumbnail python:thumbnails.get_thumbnail('128x128', 'jpeg');"
-				 tal:attributes="src extension:absolute_url(thumbnail);
-								 title i18n:value.title;" title="" src="" alt="" />
-		</a>
-		<div class="margin-top-5">
-			<span i18n:translate="">Current value: </span>
-			<span tal:content="value/content_type"></span>
-			&nbsp;&ndash;&nbsp;
-			<span tal:content="python:'%d x %d' % value.get_image_size()"></span>
-			&nbsp;&ndash;&nbsp;
-			<span tal:content="python:view.get_human_size(value.get_size())"></span>
-			<br />
-			<div class="btn-group dropup"
-				 tal:define="actions extension:context_actions(value)"
-				 tal:omit-tag="not:actions">
-				<tal:loop repeat="viewlet actions/viewlets"
-						  content="structure viewlet/render">
-				</tal:loop>
-				<a class="btn btn-xs btn-primary" target="download_window"
-				   tal:define="href extension:absolute_url(value)"
-				   tal:attributes="href string:${href}?download=1&_=${view/timestamp}"
-				   i18n:translate="">
-					Download
+		<tal:if condition="python:value.content_type.startswith('image/')">
+			<a class="fancybox hint pull-left margin-5 margin-right-10" data-toggle
+			   data-ams-fancybox-type="image"
+			   data-ams-hint-gravity="e"
+			   data-ams-hint-offset="5"
+			   tal:define="thumbnail python:view.get_thumbnail('128x128');
+						   target python:view.get_thumbnail('800x600');"
+			   tal:attributes="href extension:absolute_url(target);"
+			   title="Zoom image" i18n:attributes="title">
+				<img class="thumbnail"
+					 tal:attributes="src extension:absolute_url(thumbnail);
+									 title i18n:value.title;" title="" src="" alt="" />
+			</a>
+			<div class="margin-top-5">
+				<span i18n:translate="">Current value: </span>
+				<span tal:content="value/content_type"></span>
+				&nbsp;&ndash;&nbsp;
+				<span tal:content="python:'%d x %d' % value.get_image_size()"></span>
+				&nbsp;&ndash;&nbsp;
+				<span tal:content="python:view.get_human_size(value.get_size())"></span>
+				<br />
+				<div class="btn-group dropup"
+					 tal:define="actions extension:context_actions(value)"
+					 tal:omit-tag="not:actions">
+					<tal:loop repeat="viewlet actions/viewlets"
+							  content="structure viewlet/render">
+					</tal:loop>
+					<a class="btn btn-xs btn-primary" target="download_window"
+					   tal:define="href extension:absolute_url(value)"
+					   tal:attributes="href string:${href}?download=1&_=${view/timestamp}"
+					   i18n:translate="">
+						Download
+					</a>
+				</div>
+			</div>
+		</tal:if>
+		<tal:if condition="not:python:value.content_type.startswith('image/')">
+			<div class="pull-left margin-5 margin-right-10">
+				<a tal:define="target view/get_thumbnail_target"
+				   tal:omit-tag="not:target"
+				   tal:attributes="href target" data-toggle="modal">
+					<img class="thumbnail no-border"
+						 tal:attributes="src view/get_thumbnail" />
 				</a>
 			</div>
-		</div>
+			<div class="margin-top-5">
+				<span i18n:translate="">Current value: </span>
+				<span tal:content="value/content_type"></span>
+				&nbsp;&ndash;&nbsp;
+				<span tal:content="python:view.get_human_size(value.get_size())"></span>
+				<br />
+				<div class="btn-group dropup"
+					 tal:define="actions extension:context_actions(value)"
+					 tal:omit-tag="not:actions">
+					<tal:loop repeat="viewlet actions/viewlets"
+							  content="structure viewlet/render">
+					</tal:loop>
+					<a class="btn btn-xs btn-primary" target="download_window"
+					   tal:define="href extension:absolute_url(value)"
+					   tal:attributes="href string:${href}?download=1&_=${view/timestamp}"
+					   i18n:translate="">
+						Download
+					</a>
+				</div>
+			</div>
+		</tal:if>
 	</div>
 </i18n:block>