Dmitriy Rabotyagov 2bea2114fb Address RemovedInDjango40Warning (2)
django.utils.translation.ugettext(), ugettext_lazy(), ugettext_noop(),
ungettext(), and ungettext_lazy() are deprecated in favor of the
functions that they’re aliases for: django.utils.translation.gettext(),
gettext_lazy(), gettext_noop(), ngettext(), and ngettext_lazy().

On top of that django.conf.urls.url() is deprecated in favor of
django.urls.re_path()

Since Horizon is using Django>4.0, it's highly important to cover these
issues for upcoming release.

https: //docs.djangoproject.com/en/4.0/releases/3.0/#id3
Change-Id: Ibefe848cf73a31608ce5e71f4847b741ec16f8ad
2024-05-16 10:39:34 +02:00

100 lines
3.6 KiB
Python

# Copyright (c) 2016 Catalyst IT Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from django.utils.translation import gettext_lazy as _
from horizon import exceptions
from horizon import tabs
from adjutant_ui.api import adjutant
from adjutant_ui.api.adjutant import AdjutantApiError
from adjutant_ui.content.notifications import tables as notification_tables
class UnacknowledgedNotificationsTab(tabs.TableTab):
table_classes = (notification_tables.NotificationTable,)
template_name = 'horizon/common/_detail_table.html'
page_title = _("Unacknowledged Notifications")
name = _('Unacknowledged')
slug = 'unacknowledged'
filters = {'acknowledged': {'exact': False}}
_prev = False
_more = False
_page = 1
def get_notification_table_data(self):
notifications = []
self._page = self.request.GET.get(
self.table_classes[0]._meta.pagination_param, 1)
try:
notifications, self._prev, self._more = adjutant.notification_list(
self.request, filters=self.filters, page=self._page)
except AdjutantApiError as e:
if e.message != "Empty Page":
raise
try:
self._page = 1
notifications, self._prev, self._more = \
adjutant.notification_list(
self.request, filters=self.filters,
page=self._page)
except Exception:
exceptions.handle(
self.request, _('Failed to list notifications.'))
except Exception:
exceptions.handle(self.request, _('Failed to list notifications.'))
return notifications
def has_prev_data(self, table):
table.page = self._page
return self._prev
def has_more_data(self, table):
table.page = self._page
return self._more
class AcknowlededNotificationsTab(UnacknowledgedNotificationsTab):
table_classes = (notification_tables.AcknowlegedNotificationTable,)
page_title = _("Acknowleged Notifications")
name = _('Acknowleged')
slug = 'acknowledged'
filters = {'acknowledged': {'exact': True}}
def get_acknowleged_table_data(self):
notifications = []
self._page = self.request.GET.get(
self.table_classes[0]._meta.pagination_param, 1)
try:
notifications, self._prev, self._more = adjutant.notification_list(
self.request, filters=self.filters, page=self._page)
except Exception:
exceptions.handle(self.request, _('Failed to list notifications.'))
return notifications
class NotificationTabGroup(tabs.TabGroup):
slug = "notifications"
tabs = (UnacknowledgedNotificationsTab, AcknowlededNotificationsTab, )
sticky = True
def get_selected_tab(self):
super(NotificationTabGroup, self).get_selected_tab()
if not self._selected:
for tab in self.tabs:
param = tab.table_classes[0]._meta.pagination_param
if self.request.GET.get(param):
self._selected = self.get_tab(tab.slug)
return self._selected