diff --git a/monitoring/api/monitor.py b/monitoring/api/monitor.py index a57e8648..445e037f 100644 --- a/monitoring/api/monitor.py +++ b/monitoring/api/monitor.py @@ -106,7 +106,8 @@ def notification_create(request, **kwargs): def notification_update(request, notification_id, **kwargs): - return monclient(request).notifications.update(notification_id, **kwargs) + return monclient(request).notifications. \ + update(notification_id=notification_id, **kwargs) def metrics_list(request, marker=None, paginate=False): diff --git a/monitoring/notifications/forms.py b/monitoring/notifications/forms.py index 59f63607..02dce512 100644 --- a/monitoring/notifications/forms.py +++ b/monitoring/notifications/forms.py @@ -101,3 +101,28 @@ class DetailMethodForm(BaseNotificationMethodForm): def handle(self, request, data): return True + + +class EditMethodForm(BaseNotificationMethodForm): + def __init__(self, request, *args, **kwargs): + super(EditMethodForm, self).__init__(request, *args, **kwargs) + super(EditMethodForm, self)._init_fields(readOnly=False) + + def handle(self, request, data): + try: + kwargs = {} + kwargs['notification_id'] = self.initial['id'] + kwargs['name'] = data['name'] + kwargs['type'] = data['type'] + kwargs['address'] = data['address'] + api.monitor.notification_update( + request, + **kwargs + ) + messages.success(request, + _('Notification has been edited successfully.')) + except Exception as e: + exceptions.handle(request, + _('Unable to edit the notification: %s') % e) + return False + return True diff --git a/monitoring/notifications/tables.py b/monitoring/notifications/tables.py index 54101008..fa35ca07 100644 --- a/monitoring/notifications/tables.py +++ b/monitoring/notifications/tables.py @@ -67,7 +67,7 @@ class EditNotification(tables.LinkAction): def get_link_url(self, datum): return reverse(constants.URL_PREFIX + 'notification_edit', - datum['id'], ) + args=(datum['id'], )) def allowed(self, request, datum=None): return True @@ -87,5 +87,5 @@ class NotificationsTable(tables.DataTable): class Meta: name = "notifications" verbose_name = _("Notifications") - row_actions = (DeleteNotification, ) + row_actions = (EditNotification, DeleteNotification, ) table_actions = (CreateNotification, ) diff --git a/monitoring/notifications/templates/notifications/_edit.html b/monitoring/notifications/templates/notifications/_edit.html new file mode 100644 index 00000000..1898c1d4 --- /dev/null +++ b/monitoring/notifications/templates/notifications/_edit.html @@ -0,0 +1,24 @@ +{% extends "horizon/common/_modal_form.html" %} +{% load i18n %} +{% load url from future %} + +{% block form_id %}edit_method_form{% endblock %} +{% block form_action %}{{ action_url }}{% endblock %} + +{% block modal-header %}{% trans "Edit Alarm" %}{% endblock %} + +{% block modal-body %} +
{% blocktrans %} + The Name field is used to identify the notification method. + {% endblocktrans %}
+ + +{% endblock %} + +{% block modal-footer %} + + {% trans "Cancel" %} +{% endblock %} diff --git a/monitoring/notifications/templates/notifications/edit.html b/monitoring/notifications/templates/notifications/edit.html new file mode 100644 index 00000000..a14e4343 --- /dev/null +++ b/monitoring/notifications/templates/notifications/edit.html @@ -0,0 +1,11 @@ +{% extends 'base.html' %} +{% load i18n %} +{% block title %}{% trans 'Create Notification' %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" with title="Create Notification" %} +{% endblock page_header %} + +{% block main %} + {% include 'overcloud/notifications/_edit.html' %} +{% endblock %} diff --git a/monitoring/notifications/urls.py b/monitoring/notifications/urls.py index 910adc19..a4b41aca 100644 --- a/monitoring/notifications/urls.py +++ b/monitoring/notifications/urls.py @@ -24,7 +24,7 @@ urlpatterns = patterns( url(r'^notification_create$', views.NotificationCreateView.as_view(), name='notification_create'), - # url(r'^notification_edit/(?P