Added Notification update
This commit is contained in:
parent
4a881c3d70
commit
3cb953c1b0
@ -106,7 +106,8 @@ def notification_create(request, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def notification_update(request, notification_id, **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):
|
def metrics_list(request, marker=None, paginate=False):
|
||||||
|
@ -101,3 +101,28 @@ class DetailMethodForm(BaseNotificationMethodForm):
|
|||||||
|
|
||||||
def handle(self, request, data):
|
def handle(self, request, data):
|
||||||
return True
|
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
|
||||||
|
@ -67,7 +67,7 @@ class EditNotification(tables.LinkAction):
|
|||||||
|
|
||||||
def get_link_url(self, datum):
|
def get_link_url(self, datum):
|
||||||
return reverse(constants.URL_PREFIX + 'notification_edit',
|
return reverse(constants.URL_PREFIX + 'notification_edit',
|
||||||
datum['id'], )
|
args=(datum['id'], ))
|
||||||
|
|
||||||
def allowed(self, request, datum=None):
|
def allowed(self, request, datum=None):
|
||||||
return True
|
return True
|
||||||
@ -87,5 +87,5 @@ class NotificationsTable(tables.DataTable):
|
|||||||
class Meta:
|
class Meta:
|
||||||
name = "notifications"
|
name = "notifications"
|
||||||
verbose_name = _("Notifications")
|
verbose_name = _("Notifications")
|
||||||
row_actions = (DeleteNotification, )
|
row_actions = (EditNotification, DeleteNotification, )
|
||||||
table_actions = (CreateNotification, )
|
table_actions = (CreateNotification, )
|
||||||
|
24
monitoring/notifications/templates/notifications/_edit.html
Normal file
24
monitoring/notifications/templates/notifications/_edit.html
Normal file
@ -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 %}
|
||||||
|
<h3>{% trans "Description" %}:</h3>
|
||||||
|
<p>{% blocktrans %}
|
||||||
|
The Name field is used to identify the notification method.
|
||||||
|
{% endblocktrans %}</p>
|
||||||
|
<fieldset>
|
||||||
|
{% include "horizon/common/_form_fields.html" %}
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block modal-footer %}
|
||||||
|
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Save Notification" %}" />
|
||||||
|
<a href="{{ cancel_url }}" class="btn secondary cancel close">{% trans "Cancel" %}</a>
|
||||||
|
{% endblock %}
|
11
monitoring/notifications/templates/notifications/edit.html
Normal file
11
monitoring/notifications/templates/notifications/edit.html
Normal file
@ -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 %}
|
@ -24,7 +24,7 @@ urlpatterns = patterns(
|
|||||||
url(r'^notification_create$',
|
url(r'^notification_create$',
|
||||||
views.NotificationCreateView.as_view(),
|
views.NotificationCreateView.as_view(),
|
||||||
name='notification_create'),
|
name='notification_create'),
|
||||||
# url(r'^notification_edit/(?P<id>[^/]+)$',
|
url(r'^notification_edit/(?P<id>[^/]+)$',
|
||||||
# views.NotificationEditView.as_view(),
|
views.NotificationEditView.as_view(),
|
||||||
# name='notification_edit'),
|
name='notification_edit'),
|
||||||
)
|
)
|
||||||
|
@ -20,10 +20,11 @@ from django.contrib import messages
|
|||||||
from django.core.urlresolvers import reverse_lazy, reverse # noqa
|
from django.core.urlresolvers import reverse_lazy, reverse # noqa
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
|
||||||
|
from horizon import exceptions
|
||||||
from horizon import forms
|
from horizon import forms
|
||||||
from horizon import tables
|
from horizon import tables
|
||||||
|
|
||||||
from . import forms as alarm_forms
|
from . import forms as notification_forms
|
||||||
from . import constants
|
from . import constants
|
||||||
|
|
||||||
from monitoring import api
|
from monitoring import api
|
||||||
@ -53,7 +54,7 @@ class IndexView(tables.DataTableView):
|
|||||||
|
|
||||||
|
|
||||||
class NotificationCreateView(forms.ModalFormView):
|
class NotificationCreateView(forms.ModalFormView):
|
||||||
form_class = alarm_forms.CreateMethodForm
|
form_class = notification_forms.CreateMethodForm
|
||||||
template_name = constants.TEMPLATE_PREFIX + 'create.html'
|
template_name = constants.TEMPLATE_PREFIX + 'create.html'
|
||||||
success_url = reverse_lazy(constants.URL_PREFIX + 'index')
|
success_url = reverse_lazy(constants.URL_PREFIX + 'index')
|
||||||
|
|
||||||
@ -64,3 +65,41 @@ class NotificationCreateView(forms.ModalFormView):
|
|||||||
action = constants.URL_PREFIX + 'notification_create'
|
action = constants.URL_PREFIX + 'notification_create'
|
||||||
context["action_url"] = reverse(action)
|
context["action_url"] = reverse(action)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class NotificationEditView(forms.ModalFormView):
|
||||||
|
form_class = notification_forms.EditMethodForm
|
||||||
|
template_name = constants.TEMPLATE_PREFIX + 'edit.html'
|
||||||
|
|
||||||
|
def dispatch(self, *args, **kwargs):
|
||||||
|
return super(NotificationEditView, self).dispatch(*args, **kwargs)
|
||||||
|
|
||||||
|
def get_object(self):
|
||||||
|
id = self.kwargs['id']
|
||||||
|
try:
|
||||||
|
if hasattr(self, "_object"):
|
||||||
|
return self._object
|
||||||
|
self._object = None
|
||||||
|
self._object = api.monitor.notification_get(self.request, id)
|
||||||
|
return self._object
|
||||||
|
except Exception:
|
||||||
|
redirect = reverse(constants.URL_PREFIX + 'index')
|
||||||
|
exceptions.handle(self.request,
|
||||||
|
_('Unable to retrieve notification details.'),
|
||||||
|
redirect=redirect)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
self.notification = self.get_object()
|
||||||
|
return self.notification
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super(NotificationEditView, self).get_context_data(**kwargs)
|
||||||
|
id = self.kwargs['id']
|
||||||
|
context["cancel_url"] = self.get_success_url()
|
||||||
|
context["action_url"] = reverse(constants.URL_PREFIX +
|
||||||
|
'notification_edit', args=(id,))
|
||||||
|
return context
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return reverse_lazy(constants.URL_PREFIX + 'index',)
|
||||||
|
Loading…
Reference in New Issue
Block a user