When specifying a FileField? widget and assigning to it a validator of FieldStorageUploadConverter? it doesn't allow the field to be made optional by specifying "not_empty=False" on the validator. The following patch accomplishes that:
Index: validators.py
===================================================================
--- validators.py (revisão 4084)
+++ validators.py (cópia de trabalho)
@@ -177,13 +177,17 @@
# see #1464357 on FE bugtracker (http://tinyurl.com/lm9ae).
# Custom version of FieldStorage validator that does not break FE schema validator.
class FieldStorageUploadConverter(TgFancyValidator):
+ def __init__(self, *args, **kwargs):
+ super(TgFancyValidator, self).__init__(*args, **kwargs)
+ self.not_empty = kwargs.get('not_empty')
+
def to_python(self, value, state=None):
if isinstance(value, cgi.FieldStorage):
if value.filename:
return value
- raise Invalid('invalid', value, state)
- else:
- return value
+ if self.not_empty:
+ raise Invalid('invalid', value, state)
+ return value
# For translated messages that are not wrapped in a Validator.messages
# dictionary, we need to reinstate the Turbogears gettext function under
If you agree with this change, I'll commit it to the code.