--- a/src/pyams_file/interfaces/__init__.py Mon Feb 05 16:28:59 2018 +0100
+++ b/src/pyams_file/interfaces/__init__.py Tue Feb 06 13:57:26 2018 +0100
@@ -174,7 +174,15 @@
"""File field widget"""
-class IImageWidget(IFileWidget):
+class IMediaWidget(IFileWidget):
+ """Media file widget"""
+
+
+class IThumbnailMediaWidget(IMediaWidget):
+ """Media file widget with thumbnail selection"""
+
+
+class IImageWidget(IMediaWidget):
"""Image field widget"""
--- a/src/pyams_file/widget/__init__.py Mon Feb 05 16:28:59 2018 +0100
+++ b/src/pyams_file/widget/__init__.py Tue Feb 06 13:57:26 2018 +0100
@@ -19,8 +19,8 @@
from datetime import datetime
# import interfaces
-from pyams_file.interfaces import IFileField, IFileWidget, IImageField, IImageWidget, \
- IThumbnailImageWidget, IThumbnailImageField, DELETED_FILE, IThumbnail
+from pyams_file.interfaces import IFileField, IFileWidget, IMediaField, IMediaWidget, \
+ IThumbnailMediaField, IThumbnailMediaWidget, DELETED_FILE, IThumbnail
from pyams_form.interfaces.form import IFormLayer
from pyramid.interfaces import IView
from z3c.form.interfaces import NOT_CHANGED, IFieldWidget, IDataConverter
@@ -127,23 +127,23 @@
# Image widgets
#
-@widgettemplate_config(mode='input', template='templates/image-input.pt', widget=IImageWidget, layer=IFormLayer)
-@widgettemplate_config(mode='display', template='templates/image-display.pt', widget=IImageWidget, layer=IFormLayer)
-@implementer_only(IImageWidget)
-class ImageWidget(FileWidget):
- """Image widget"""
+@widgettemplate_config(mode='input', template='templates/media-input.pt', widget=IMediaWidget, layer=IFormLayer)
+@widgettemplate_config(mode='display', template='templates/media-display.pt', widget=IMediaWidget, layer=IFormLayer)
+@implementer_only(IMediaWidget)
+class MediaWidget(FileWidget):
+ """Media file widget"""
-@adapter_config(context=(IImageField, IFormLayer), provides=IFieldWidget)
-def ImageFieldWidget(field, request):
- return FieldWidget(field, ImageWidget(request))
+@adapter_config(context=(IMediaField, IFormLayer), provides=IFieldWidget)
+def MediaFieldWidget(field, request):
+ return FieldWidget(field, MediaWidget(request))
-@implementer_only(IThumbnailImageWidget)
-class ThumbnailImageWidget(ImageWidget):
- """Image widget with thumbnail images selection"""
+@implementer_only(IThumbnailMediaWidget)
+class ThumbnailMediaWidget(MediaWidget):
+ """Media widget with thumbnail images selection"""
-@adapter_config(context=(IThumbnailImageField, IFormLayer), provides=IFieldWidget)
-def ThumbnailImageFieldWidget(field, request):
- return FieldWidget(field, ThumbnailImageWidget(request))
+@adapter_config(context=(IThumbnailMediaField, IFormLayer), provides=IFieldWidget)
+def ThumbnailMediaFieldWidget(field, request):
+ return FieldWidget(field, ThumbnailMediaWidget(request))
--- a/src/pyams_file/widget/templates/image-display.pt Mon Feb 05 16:28:59 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-<i18n:block domain="pyams_file">
- <div class="current-value"
- tal:define="value view/current_value"
- tal:condition="value">
- <a class="fancybox hint pull-left margin-left-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');"
- tal:attributes="src extension:absolute_url(thumbnail);
- title i18n:value.title;" title="" src="" alt="" />
- </a>
- <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>
- –
- <span tal:content="python:'%d x %d' % value.get_image_size()"></span>
- –
- <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>
- –
- <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 Mon Feb 05 16:28:59 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,89 +0,0 @@
-<i18n:block domain="pyams_file">
- <div class="input-file">
- <div class="button">
- <input type="file" onchange="this.parentNode.nextSibling.value = this.value;"
- tal:attributes="name view/name;
- id view/id;" />
- <tal:var i18n:translate="">Browse...</tal:var>
- </div><input type="text" placeholder="Please select a file..." readonly i18n:attributes="placeholder" />
- </div>
- <div class="current-value"
- tal:define="value view/current_value"
- tal:condition="value">
- <div class="pull-right" tal:condition="view/deletable">
- <label class="checkbox">
- <input type="checkbox" value="on"
- tal:attributes="id string:${view/id}.__deleted;
- name string:${view/name}__deleted;" />
- <i></i>
- <span i18n:translate="">Delete content</span>
- </label>
- </div>
- <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>
- –
- <span tal:content="python:'%d x %d' % value.get_image_size()"></span>
- –
- <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 class="margin-top-5">
- <span i18n:translate="">Current value: </span>
- <span tal:content="value/content_type"></span>
- –
- <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>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_file/widget/templates/media-display.pt Tue Feb 06 13:57:26 2018 +0100
@@ -0,0 +1,48 @@
+<i18n:block domain="pyams_file">
+ <div class="current-value"
+ tal:define="value view/current_value"
+ tal:condition="value">
+ <a class="fancybox hint pull-left margin-left-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');"
+ tal:attributes="src extension:absolute_url(thumbnail);
+ title i18n:value.title;" title="" src="" alt="" />
+ </a>
+ <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>
+ –
+ <span tal:content="python:'%d x %d' % value.get_image_size()"></span>
+ –
+ <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>
+ –
+ <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>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_file/widget/templates/media-input.pt Tue Feb 06 13:57:26 2018 +0100
@@ -0,0 +1,89 @@
+<i18n:block domain="pyams_file">
+ <div class="input-file">
+ <div class="button">
+ <input type="file" onchange="this.parentNode.nextSibling.value = this.value;"
+ tal:attributes="name view/name;
+ id view/id;" />
+ <tal:var i18n:translate="">Browse...</tal:var>
+ </div><input type="text" placeholder="Please select a file..." readonly i18n:attributes="placeholder" />
+ </div>
+ <div class="current-value"
+ tal:define="value view/current_value"
+ tal:condition="value">
+ <div class="pull-right" tal:condition="view/deletable">
+ <label class="checkbox">
+ <input type="checkbox" value="on"
+ tal:attributes="id string:${view/id}.__deleted;
+ name string:${view/name}__deleted;" />
+ <i></i>
+ <span i18n:translate="">Delete content</span>
+ </label>
+ </div>
+ <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>
+ –
+ <span tal:content="python:'%d x %d' % value.get_image_size()"></span>
+ –
+ <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 class="margin-top-5">
+ <span i18n:translate="">Current value: </span>
+ <span tal:content="value/content_type"></span>
+ –
+ <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>