diff options
Diffstat (limited to 'src/workflow/forms.py')
-rw-r--r-- | src/workflow/forms.py | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/workflow/forms.py b/src/workflow/forms.py index ee44ecd..4d5e9e2 100644 --- a/src/workflow/forms.py +++ b/src/workflow/forms.py @@ -15,6 +15,7 @@ from django.template.loader import render_to_string from django.forms.widgets import NumberInput import json +import urllib from account.models import Lab from account.models import UserProfile @@ -120,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") @@ -270,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: @@ -428,6 +438,24 @@ class ConfirmationForm(forms.Form): ) +def validate_step(value): + if value not in ["prev", "next", "current"]: + raise ValidationError(str(value) + " is not allowed") + + +def validate_step_form(value): + try: + urllib.parse.unquote_plus(value) + except Exception: + raise ValidationError("Value is not url encoded data") + + +class ManagerForm(forms.Form): + step = forms.CharField(widget=forms.widgets.HiddenInput, validators=[validate_step]) + step_form = forms.CharField(widget=forms.widgets.HiddenInput, validators=[validate_step_form]) + # other fields? + + class OPNFVSelectionForm(forms.Form): installer = forms.ModelChoiceField(queryset=Installer.objects.all(), required=True) scenario = forms.ModelChoiceField(queryset=Scenario.objects.all(), required=True) |