Validate expression and return better errors to user
Change-Id: Ice1775412aa93776d7c07f7851abc1e255aa3edd
This commit is contained in:
parent
3730103e65
commit
b959feffe7
|
@ -270,6 +270,16 @@ class BaseAlarmForm(forms.SelfHandlingForm):
|
||||||
|
|
||||||
self.fields['notifications'].choices = notification_choices
|
self.fields['notifications'].choices = notification_choices
|
||||||
|
|
||||||
|
def clean_expression(self):
|
||||||
|
data = self.cleaned_data['expression']
|
||||||
|
value = data.split(' ')[2]
|
||||||
|
if not value.isdigit():
|
||||||
|
raise forms.ValidationError("Value must be an integer")
|
||||||
|
|
||||||
|
# Always return the cleaned data, whether you have changed it or
|
||||||
|
# not.
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
class CreateAlarmForm(BaseAlarmForm):
|
class CreateAlarmForm(BaseAlarmForm):
|
||||||
def __init__(self, request, *args, **kwargs):
|
def __init__(self, request, *args, **kwargs):
|
||||||
|
@ -293,7 +303,7 @@ class CreateAlarmForm(BaseAlarmForm):
|
||||||
messages.success(request,
|
messages.success(request,
|
||||||
_('Alarm has been created successfully.'))
|
_('Alarm has been created successfully.'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
exceptions.handle(request, _('Unable to create the alarm: %s') % e)
|
exceptions.handle(request, _('Unable to create the alarm: %s') % e.message)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue