--- a/src/pyams_file/configure.zcml Fri Mar 20 17:30:42 2015 +0100
+++ b/src/pyams_file/configure.zcml Fri Mar 20 17:31:05 2015 +0100
@@ -9,10 +9,6 @@
<i18n:registerTranslations directory="locales" />
- <!-- Widgets package -->
- <include package=".widget" />
-
-
<configure zcml:condition="installed pyams_zmi">
<include package=".zmi" />
</configure>
--- a/src/pyams_file/widget/__init__.py Fri Mar 20 17:30:42 2015 +0100
+++ b/src/pyams_file/widget/__init__.py Fri Mar 20 17:31:05 2015 +0100
@@ -20,9 +20,10 @@
from pyams_file.interfaces import IFileField, IFileWidget, IImageField, IImageWidget, \
IThumnailImageWidget, IThumbnailImageField, DELETED_FILE
from pyams_form.interfaces.form import IFormLayer
-from z3c.form.interfaces import IFieldWidget, NOT_CHANGED, IDataConverter
+from z3c.form.interfaces import NOT_CHANGED, IFieldWidget, IDataConverter
# import packages
+from pyams_form.widget import widgettemplate_config
from pyams_utils.adapter import adapter_config
from z3c.form.browser.file import FileWidget as BaseFileWidget
from z3c.form.converter import BaseDataConverter
@@ -51,26 +52,34 @@
return toBytes(value)
+@widgettemplate_config(mode='input', template='templates/file-input.pt', widget=IFileWidget, layer=IFormLayer)
+@widgettemplate_config(mode='display', template='templates/file-display.pt', widget=IFileWidget, layer=IFormLayer)
@implementer_only(IFileWidget)
class FileWidget(BaseFileWidget):
"""File widget"""
- label_css_class = 'input input-file'
-
@property
def current_value(self):
if self.form.ignoreContext:
return None
- return self.field.get(self.context)
+ lang = getattr(self, 'lang', None)
+ if lang is None:
+ return self.field.get(self.context)
+ else:
+ value = self.field.get(self.context)
+ if isinstance(value, dict):
+ value = value.get(lang)
+ return value
@property
def deletable(self):
if self.required:
return False
- elif self.value is NOT_CHANGED:
- return self.current_value is not None
+ if not self.ignoreContext:
+ value = self.current_value
else:
- return self.value is not None
+ value = self.value
+ return bool(value)
@adapter_config(context=(IFileField, IFormLayer), provides=IFieldWidget)
@@ -78,6 +87,8 @@
return FieldWidget(field, FileWidget(request))
+@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"""
--- a/src/pyams_file/widget/configure.zcml Fri Mar 20 17:30:42 2015 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-<configure
- xmlns="http://pylonshq.com/pyramid"
- xmlns:z3c="http://namespaces.zope.org/z3c">
-
- <include package="pyramid_zcml"/>
- <include package="z3c.form" file="meta.zcml" />
-
-
- <!-- File widgets -->
- <z3c:widgetTemplate
- mode="input"
- template="templates/file-input.pt"
- widget="pyams_file.interfaces.IFileWidget"
- layer="pyams_form.interfaces.form.IFormLayer" />
-
- <z3c:widgetTemplate
- mode="display"
- template="templates/file-display.pt"
- widget="pyams_file.interfaces.IFileWidget"
- layer="pyams_form.interfaces.form.IFormLayer" />
-
-
- <!-- Image widgets -->
- <z3c:widgetTemplate
- mode="input"
- template="templates/image-input.pt"
- widget="pyams_file.interfaces.IImageWidget"
- layer="pyams_form.interfaces.form.IFormLayer" />
-
- <z3c:widgetTemplate
- mode="display"
- template="templates/image-display.pt"
- widget="pyams_file.interfaces.IImageWidget"
- layer="pyams_form.interfaces.form.IFormLayer" />
-
-</configure>
--- a/src/pyams_file/widget/templates/file-input.pt Fri Mar 20 17:30:42 2015 +0100
+++ b/src/pyams_file/widget/templates/file-input.pt Fri Mar 20 17:31:05 2015 +0100
@@ -1,4 +1,4 @@
-<i18n:block domain="pyams_file">
+<div class="input-file" i18n:domain="pyams_file">
<div>
<div class="button">
<input type="file" onchange="this.parentNode.nextSibling.value = this.value;"
@@ -44,4 +44,4 @@
</div>
</div>
</div>
-</i18n:block>
+</div>
--- a/src/pyams_file/widget/templates/image-input.pt Fri Mar 20 17:30:42 2015 +0100
+++ b/src/pyams_file/widget/templates/image-input.pt Fri Mar 20 17:31:05 2015 +0100
@@ -1,4 +1,4 @@
-<i18n:block domain="pyams_file">
+<div class="input-file" i18n:domain="pyams_file">
<div>
<div class="button">
<input type="file" onchange="this.parentNode.nextSibling.value = this.value;"
@@ -19,7 +19,7 @@
<div class="current-value"
tal:define="value view/current_value"
tal:condition="value">
- <a class="fancybox hint pull-left" data-toggle
+ <a class="fancybox hint pull-left margin-left-5 margin-right-10" data-toggle
data-ams-fancybox-type="image"
data-ams-hint-gravity="e"
tal:define="thumbnails extension:thumbnails(value);
@@ -57,4 +57,4 @@
</div>
</div>
</div>
-</i18n:block>
+</div>