From ce5288068bc74dbb06a096f651c9fbb572af3ccc Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Sat, 25 Jul 2015 22:28:25 +0200 Subject: [PATCH] If the user doesn't upload a file, and the field is not required, don't raise a ValidationError. --- src/formdefinition.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/formdefinition.py b/src/formdefinition.py index 35be8de..03ec5d7 100644 --- a/src/formdefinition.py +++ b/src/formdefinition.py @@ -244,7 +244,11 @@ class FormDefinition(object): try: value = form_values[field_def['name']] except KeyError: - raise ValidationError("Invalid file upload") + # Field is missing. Check if it's required. + if 'required' in field_def and field_def['required'] == True: + raise ValidationError("Invalid file upload") + else: + return '' field_name = field_def['name'] upload_fname = form_values[u'{0}__name'.format(field_name)]