Merge "Fix validators for creating and editing notifications"
This commit is contained in:
commit
4f13d35966
@ -65,32 +65,28 @@ class BaseNotificationMethodForm(forms.SelfHandlingForm):
|
||||
help_text=_("The email/url address to notify."))
|
||||
self.fields['period'] = forms.IntegerField(label=_("Period"),
|
||||
min_value=0,
|
||||
max_value=60,
|
||||
initial=0,
|
||||
required=required,
|
||||
help_text=_("The notification period."))
|
||||
|
||||
def clean_period(self):
|
||||
'''Check to make sure period is zero unless type is WEBHOOK.
|
||||
For WEBHOOK period must be set to 0 or 60.
|
||||
'''
|
||||
data = self.cleaned_data
|
||||
if data['type'] != constants.NotificationType.WEBHOOK and data['period'] != 0:
|
||||
raise forms.ValidationError(_("Period must be zero except for type webhook."))
|
||||
raise forms.ValidationError(
|
||||
_('Period must be zero except for type webhook.'))
|
||||
elif (data['type'] == constants.NotificationType.WEBHOOK and
|
||||
data['period'] not in [0, 60]):
|
||||
raise forms.ValidationError(_('Period must be 0 or 60.'))
|
||||
|
||||
return data['period']
|
||||
|
||||
@cached_property
|
||||
def notification_types(self):
|
||||
return api.monitor.notification_type_list(self.request)
|
||||
|
||||
|
||||
class CreateMethodForm(BaseNotificationMethodForm):
|
||||
def __init__(self, request, *args, **kwargs):
|
||||
super(CreateMethodForm, self).__init__(request, *args, **kwargs)
|
||||
super(CreateMethodForm, self)._init_fields(readOnly=False)
|
||||
|
||||
def clean_address(self):
|
||||
'''Check to make sure address is the correct format depending on the
|
||||
type of notification
|
||||
type of notification.
|
||||
'''
|
||||
data = self.cleaned_data
|
||||
if data['type'] == constants.NotificationType.EMAIL:
|
||||
@ -102,6 +98,16 @@ class CreateMethodForm(BaseNotificationMethodForm):
|
||||
|
||||
return data['address']
|
||||
|
||||
@cached_property
|
||||
def notification_types(self):
|
||||
return api.monitor.notification_type_list(self.request)
|
||||
|
||||
|
||||
class CreateMethodForm(BaseNotificationMethodForm):
|
||||
def __init__(self, request, *args, **kwargs):
|
||||
super(CreateMethodForm, self).__init__(request, *args, **kwargs)
|
||||
super(CreateMethodForm, self)._init_fields(readOnly=False)
|
||||
|
||||
def handle(self, request, data):
|
||||
try:
|
||||
api.monitor.notification_create(
|
||||
|
Loading…
Reference in New Issue
Block a user