--- a/src/pyams_i18n/schema.py Wed Jul 12 14:19:16 2017 +0200
+++ b/src/pyams_i18n/schema.py Mon Sep 11 13:39:06 2017 +0200
@@ -16,6 +16,7 @@
# import standard library
# import interfaces
+from pyams_file.interfaces import DELETED_FILE
from pyams_i18n.interfaces.schema import II18nField, II18nTextLineField, II18nTextField, II18nFileField, II18nImageField, \
II18nThumbnailImageField, II18nHTMLField
from zope.schema.interfaces import RequiredMissing
@@ -128,6 +129,18 @@
required=False),
**kwargs)
+ def _validate(self, value):
+ super(I18nField, self)._validate(value)
+ if self.required:
+ if self.default:
+ return
+ if not value:
+ raise RequiredMissing
+ for lang_value in value.values():
+ if lang_value and (lang_value is not DELETED_FILE):
+ return
+ raise RequiredMissing
+
@implementer(II18nImageField)
class I18nImageField(I18nField):
@@ -139,6 +152,18 @@
required=False),
**kwargs)
+ def _validate(self, value):
+ super(I18nField, self)._validate(value)
+ if self.required:
+ if self.default:
+ return
+ if not value:
+ raise RequiredMissing
+ for lang_value in value.values():
+ if lang_value and (lang_value is not DELETED_FILE):
+ return
+ raise RequiredMissing
+
@implementer(II18nThumbnailImageField)
class I18nThumbnailImageField(I18nField):
@@ -149,3 +174,15 @@
max_length=value_max_length,
required=False),
**kwargs)
+
+ def _validate(self, value):
+ super(I18nField, self)._validate(value)
+ if self.required:
+ if self.default:
+ return
+ if not value:
+ raise RequiredMissing
+ for lang_value in value.values():
+ if lang_value and (lang_value is not DELETED_FILE):
+ return
+ raise RequiredMissing