aboutsummaryrefslogtreecommitdiffstats
path: root/src/workflow/forms.py
diff options
context:
space:
mode:
authorParker Berberian <pberberian@iol.unh.edu>2019-07-08 16:39:54 -0400
committerParker Berberian <pberberian@iol.unh.edu>2019-07-10 09:12:20 -0400
commit38b4412f8b6cf21371b67e8de917f5a24b2bf72d (patch)
treeb19adcaf27fce5d161b226017b62ce7e91a83be2 /src/workflow/forms.py
parent35c8640a32b7c6b3b35d68367668898fdfd7d423 (diff)
Fixes and adds Tests
Fixes old tests and adds some more. Also fixes linting errors Change-Id: If84f0ed2dab5f9ffa7ce2deb92e058b0076d9154 Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
Diffstat (limited to 'src/workflow/forms.py')
-rw-r--r--src/workflow/forms.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/workflow/forms.py b/src/workflow/forms.py
index a2746f9..4d5e9e2 100644
--- a/src/workflow/forms.py
+++ b/src/workflow/forms.py
@@ -121,7 +121,12 @@ class SearchableSelectMultipleField(forms.Field):
raise ValidationError("Nothing was selected")
else:
return []
- data_as_list = json.loads(data)
+ try:
+ data_as_list = json.loads(data)
+ except json.decoder.JSONDecodeError:
+ data_as_list = None
+ if not data_as_list:
+ raise ValidationError("Contents Not JSON")
if self.selectable_limit != -1:
if len(data_as_list) > self.selectable_limit:
raise ValidationError("Too many items were selected")
@@ -271,7 +276,11 @@ class MultipleSelectFilterField(forms.Field):
super().__init__(**kwargs)
def to_python(self, value):
- return json.loads(value)
+ try:
+ return json.loads(value)
+ except json.decoder.JSONDecodeError:
+ pass
+ raise ValidationError("content is not valid JSON")
class FormUtils: