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."))
|
help_text=_("The email/url address to notify."))
|
||||||
self.fields['period'] = forms.IntegerField(label=_("Period"),
|
self.fields['period'] = forms.IntegerField(label=_("Period"),
|
||||||
min_value=0,
|
min_value=0,
|
||||||
|
max_value=60,
|
||||||
initial=0,
|
initial=0,
|
||||||
required=required,
|
required=required,
|
||||||
help_text=_("The notification period."))
|
help_text=_("The notification period."))
|
||||||
|
|
||||||
def clean_period(self):
|
def clean_period(self):
|
||||||
'''Check to make sure period is zero unless type is WEBHOOK.
|
'''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
|
data = self.cleaned_data
|
||||||
if data['type'] != constants.NotificationType.WEBHOOK and data['period'] != 0:
|
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']
|
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):
|
def clean_address(self):
|
||||||
'''Check to make sure address is the correct format depending on the
|
'''Check to make sure address is the correct format depending on the
|
||||||
type of notification
|
type of notification.
|
||||||
'''
|
'''
|
||||||
data = self.cleaned_data
|
data = self.cleaned_data
|
||||||
if data['type'] == constants.NotificationType.EMAIL:
|
if data['type'] == constants.NotificationType.EMAIL:
|
||||||
@ -102,6 +98,16 @@ class CreateMethodForm(BaseNotificationMethodForm):
|
|||||||
|
|
||||||
return data['address']
|
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):
|
def handle(self, request, data):
|
||||||
try:
|
try:
|
||||||
api.monitor.notification_create(
|
api.monitor.notification_create(
|
||||||
|
Loading…
Reference in New Issue
Block a user