From ec4aea5aaab98c072ad51af9af6d5bfd8db96b81 Mon Sep 17 00:00:00 2001 From: Yumeng Bao Date: Thu, 26 Jul 2018 14:02:20 +0800 Subject: [PATCH] Set interval parameter to optional and add validation before audit create This patch fixes dashboard bug: Oneshot Audit Create failed Change-Id: Ic3f8833a5091226abb22b8260cdc5adf8711c279 Closes-Bug: #1783683 --- watcher_dashboard/content/audits/forms.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/watcher_dashboard/content/audits/forms.py b/watcher_dashboard/content/audits/forms.py index 6c2e50e..b139368 100644 --- a/watcher_dashboard/content/audits/forms.py +++ b/watcher_dashboard/content/audits/forms.py @@ -51,7 +51,8 @@ class CreateForm(forms.SelfHandlingForm): 'data-switch-on': 'audit_type', 'data-audit_type-continuous': _("Interval (in seconds or cron" - " format)")})) + " format)")}), + required=False) failure_url = 'horizon:admin:audits:index' auto_trigger = forms.BooleanField(label=_("Auto Trigger"), required=False) @@ -81,6 +82,14 @@ class CreateForm(forms.SelfHandlingForm): choices.insert(0, ("", _("No Audit Template found"))) return choices + def clean(self): + cleaned_data = super(CreateForm, self).clean() + audit_type = cleaned_data.get('audit_type') + if audit_type == 'continuous' and not cleaned_data.get('interval'): + msg = _('Please input an interval for continuous audit') + raise forms.ValidationError(msg) + return cleaned_data + def handle(self, request, data): try: params = {'audit_template_uuid': data.get('audit_template')}