Change IntegerField to ChoiceField for notification period
Story: 2001506 Task: 6297 Change-Id: I937507e9a65dbf4cd3962c0910180464378aed00
This commit is contained in:
parent
78d764718a
commit
37ecb3ca66
@ -44,6 +44,7 @@ class BaseNotificationMethodForm(forms.SelfHandlingForm):
|
|||||||
|
|
||||||
choices = [(n['type'], n['type'].capitalize()) for n in self.notification_types]
|
choices = [(n['type'], n['type'].capitalize()) for n in self.notification_types]
|
||||||
choices = sorted(choices, key=lambda c: c[0])
|
choices = sorted(choices, key=lambda c: c[0])
|
||||||
|
period_choices = [(0, '0'), (60, '60')]
|
||||||
|
|
||||||
self.fields['name'] = forms.CharField(label=_("Name"),
|
self.fields['name'] = forms.CharField(label=_("Name"),
|
||||||
required=required,
|
required=required,
|
||||||
@ -63,24 +64,21 @@ class BaseNotificationMethodForm(forms.SelfHandlingForm):
|
|||||||
max_length="512",
|
max_length="512",
|
||||||
widget=textWidget,
|
widget=textWidget,
|
||||||
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.ChoiceField(label=_("Period"),
|
||||||
min_value=0,
|
widget=selectWidget,
|
||||||
max_value=60,
|
choices=period_choices,
|
||||||
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.
|
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(
|
raise forms.ValidationError(
|
||||||
_('Period must be zero except for type webhook.'))
|
_('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']
|
||||||
|
|
||||||
@ -115,7 +113,7 @@ class CreateMethodForm(BaseNotificationMethodForm):
|
|||||||
name=data['name'],
|
name=data['name'],
|
||||||
type=data['type'],
|
type=data['type'],
|
||||||
address=data['address'],
|
address=data['address'],
|
||||||
period=data['period'])
|
period=int(data['period']))
|
||||||
messages.success(request,
|
messages.success(request,
|
||||||
_('Notification method has been created '
|
_('Notification method has been created '
|
||||||
'successfully.'))
|
'successfully.'))
|
||||||
@ -148,7 +146,7 @@ class EditMethodForm(BaseNotificationMethodForm):
|
|||||||
kwargs['name'] = data['name']
|
kwargs['name'] = data['name']
|
||||||
kwargs['type'] = data['type']
|
kwargs['type'] = data['type']
|
||||||
kwargs['address'] = data['address']
|
kwargs['address'] = data['address']
|
||||||
kwargs['period'] = data['period']
|
kwargs['period'] = int(data['period'])
|
||||||
api.monitor.notification_update(
|
api.monitor.notification_update(
|
||||||
request,
|
request,
|
||||||
**kwargs
|
**kwargs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user