Updated file field validation against "NOT_CHANGED" value
authorThierry Florac <thierry.florac@onf.fr>
Mon, 11 Sep 2017 13:28:17 +0200
changeset 49 79afa48cc2aa
parent 48 277260b46bc7
child 50 3b2cb5046d86
Updated file field validation against "NOT_CHANGED" value
src/pyams_file/schema.py
--- a/src/pyams_file/schema.py	Mon Sep 11 13:26:57 2017 +0200
+++ b/src/pyams_file/schema.py	Mon Sep 11 13:28:17 2017 +0200
@@ -18,7 +18,7 @@
 from pyams_file.interfaces import IFile, IFileField, IMediaFile, IMediaField, IImage, IImageField, \
     IThumbnailImageField, IVideo, IVideoField, IAudio, IAudioField, DELETED_FILE
 from z3c.form.interfaces import NOT_CHANGED
-from zope.schema.interfaces import WrongType
+from zope.schema.interfaces import WrongType, RequiredMissing
 
 # import packages
 from zope.interface import implementer
@@ -32,7 +32,10 @@
     schema = IFile
 
     def _validate(self, value):
-        if (value is DELETED_FILE) or (value is NOT_CHANGED):
+        if value is DELETED_FILE:
+            if self.required and not self.default:
+                raise RequiredMissing
+        elif value is NOT_CHANGED:
             return
         elif isinstance(value, tuple):
             try: