Validate expression and return better errors to user

Change-Id: Ice1775412aa93776d7c07f7851abc1e255aa3edd
This commit is contained in:
Rob Raymond 2014-07-28 14:49:24 -06:00
parent 3730103e65
commit b959feffe7
1 changed files with 15 additions and 5 deletions

View File

@ -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