Debian Codegraph @

adjutant_ui/content/notifications/views.py

raw
1 # Copyright (c) 2016 Catalyst IT Ltd.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from django.urls import reverse
16 from django.utils.translation import gettext_lazy as _
17
18 from horizon import exceptions
19 from horizon import tabs
20 from horizon import views
21
22 from horizon.utils import memoized
23
24 from adjutant_ui.api import adjutant
25 from adjutant_ui.content.notifications import tables as notification_tables
26 from adjutant_ui.content.notifications import tabs as notification_tab
27
28
29 class IndexView(tabs.TabbedTableView):
30 tab_group_class = notification_tab.NotificationTabGroup
31 template_name = 'notifications/index.html'
32 redirect_url = 'horizon:management:notifications:index'
33 page_title = _("Admin Notifications")
34
35
36 class NotificationDetailView(views.HorizonTemplateView):
37 redirect_url = "horizon:management:notifications:index"
38 template_name = 'notifications/detail.html'
39 page_title = "Notification: {{ notification.uuid }}"
40
41 def get_context_data(self, **kwargs):
42 context = super(NotificationDetailView, self).get_context_data(
43 **kwargs)
44 notification, task = self.get_data()
45 context["notification"] = notification
46 context['task'] = task
47 context["url"] = reverse(self.redirect_url)
48 context["actions"] = self._get_actions(notification=notification)
49 return context
50
51 def _get_actions(self, notification):
52 table = notification_tables.NotificationTable(self.request)
53 return table.render_row_actions(notification)
54
55 @memoized.memoized_method
56 def get_data(self):
57 try:
58 notification = adjutant.notification_obj_get(
59 self.request, self.kwargs['notif_id'])
60 task = adjutant.task_obj_get(self.request,
61 task_id=notification.task)
62 return notification, task
63 except Exception:
64 msg = _('Unable to retrieve notification.')
65 url = reverse('horizon:management:notifications:index')
66 exceptions.handle(self.request, msg, redirect=url)