From 999bfa2a05be7ecf53a34fad92d1e6a6f2432b60 Mon Sep 17 00:00:00 2001 From: Martin Chacon Piza Date: Fri, 8 Jun 2018 12:08:42 +0200 Subject: [PATCH] Support Django 2.0 Change-Id: I559cfece3e696a83eee3cb9aeec22b6b65d34bfc story: 2002191 task: 20064 --- monitoring/alarmdefs/forms.py | 2 +- monitoring/alarmdefs/tables.py | 8 +++----- monitoring/alarmdefs/tests.py | 14 +++++--------- monitoring/alarmdefs/views.py | 4 ++-- monitoring/alarms/forms.py | 2 +- monitoring/alarms/tables.py | 23 ++++++++++------------- monitoring/alarms/tests.py | 8 ++++---- monitoring/alarms/views.py | 4 ++-- monitoring/notifications/tables.py | 8 ++++---- monitoring/notifications/tests.py | 8 ++++---- monitoring/notifications/views.py | 4 ++-- monitoring/overview/tests.py | 4 ++-- monitoring/overview/views.py | 2 +- requirements.txt | 3 ++- 14 files changed, 43 insertions(+), 51 deletions(-) diff --git a/monitoring/alarmdefs/forms.py b/monitoring/alarmdefs/forms.py index 09ec5061..81505e05 100644 --- a/monitoring/alarmdefs/forms.py +++ b/monitoring/alarmdefs/forms.py @@ -91,7 +91,7 @@ class MatchByWidget(forms.Widget): class NotificationField(forms.MultiValueField): def __init__(self, *args, **kwargs): - super(NotificationField, self).__init__(*args, **kwargs) + super(NotificationField, self).__init__(fields=(), *args, **kwargs) def _get_choices(self): return self._choices diff --git a/monitoring/alarmdefs/tables.py b/monitoring/alarmdefs/tables.py index 3a76b6f0..67773c39 100644 --- a/monitoring/alarmdefs/tables.py +++ b/monitoring/alarmdefs/tables.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from django.core import urlresolvers +from django.urls import reverse from django.utils.translation import ugettext_lazy as _ # noqa from django.utils.translation import ungettext_lazy @@ -31,8 +31,7 @@ class CreateAlarm(tables.LinkAction): ajax = True def get_link_url(self): - return urlresolvers.reverse(constants.URL_PREFIX + 'alarm_create', - args=()) + return reverse(constants.URL_PREFIX + 'alarm_create', args=()) def allowed(self, request, datum=None): return True @@ -44,8 +43,7 @@ class EditAlarm(tables.LinkAction): classes = ("ajax-modal", "btn-create") def get_link_url(self, datum): - return urlresolvers.reverse(constants.URL_PREFIX + 'alarm_edit', - args=(datum['id'], )) + return reverse(constants.URL_PREFIX + 'alarm_edit', args=(datum['id'], )) def allowed(self, request, datum=None): return True diff --git a/monitoring/alarmdefs/tests.py b/monitoring/alarmdefs/tests.py index 0d05277d..334f199b 100644 --- a/monitoring/alarmdefs/tests.py +++ b/monitoring/alarmdefs/tests.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -from django.core import urlresolvers +from django.urls import reverse from mock import patch from monitoring.alarmdefs import constants @@ -22,14 +22,10 @@ from monitoring.alarmdefs import workflows from monitoring.test import helpers -INDEX_URL = urlresolvers.reverse( - constants.URL_PREFIX + 'index') -CREATE_URL = urlresolvers.reverse( - constants.URL_PREFIX + 'alarm_create', args=()) -DETAIL_URL = urlresolvers.reverse( - constants.URL_PREFIX + 'alarm_detail', args=('12345',)) -EDIT_URL = urlresolvers.reverse( - constants.URL_PREFIX + 'alarm_edit', args=('12345',)) +INDEX_URL = reverse(constants.URL_PREFIX + 'index') +CREATE_URL = reverse(constants.URL_PREFIX + 'alarm_create', args=()) +DETAIL_URL = reverse(constants.URL_PREFIX + 'alarm_detail', args=('12345',)) +EDIT_URL = reverse(constants.URL_PREFIX + 'alarm_edit', args=('12345',)) class AlarmDefinitionsTest(helpers.TestCase): diff --git a/monitoring/alarmdefs/views.py b/monitoring/alarmdefs/views.py index b8beaecd..f3bbcafc 100644 --- a/monitoring/alarmdefs/views.py +++ b/monitoring/alarmdefs/views.py @@ -17,8 +17,8 @@ import logging from django.contrib import messages from django.core.paginator import EmptyPage from django.core.paginator import Paginator -from django.core.urlresolvers import reverse -from django.core.urlresolvers import reverse_lazy +from django.urls import reverse +from django.urls import reverse_lazy from django.utils.translation import ugettext as _ # noqa from django.views.generic import TemplateView import six diff --git a/monitoring/alarms/forms.py b/monitoring/alarms/forms.py index 98bf4953..0ea14939 100644 --- a/monitoring/alarms/forms.py +++ b/monitoring/alarms/forms.py @@ -89,7 +89,7 @@ class SimpleExpressionWidget(django_forms.MultiWidget): class NotificationField(forms.MultiValueField): def __init__(self, *args, **kwargs): - super(NotificationField, self).__init__(*args, **kwargs) + super(NotificationField, self).__init__(fields=(), *args, **kwargs) def _get_choices(self): return self._choices diff --git a/monitoring/alarms/tables.py b/monitoring/alarms/tables.py index aa4a5568..ad772be2 100644 --- a/monitoring/alarms/tables.py +++ b/monitoring/alarms/tables.py @@ -15,9 +15,9 @@ import json -from django.core import urlresolvers -from django.core.urlresolvers import reverse_lazy from django import template +from django.urls import reverse +from django.urls import reverse_lazy from django.utils.translation import ugettext_lazy as _ # noqa from django.utils.translation import ungettext_lazy @@ -108,9 +108,8 @@ class ShowAlarmHistory(tables.LinkAction): classes = ('btn-edit',) def get_link_url(self, datum): - return urlresolvers.reverse(constants.URL_PREFIX + 'history', - args=(datum['alarm_definition']['id'], - datum['id'], )) + return reverse(constants.URL_PREFIX + 'history', + args=(datum['alarm_definition']['id'], datum['id'], )) def allowed(self, request, datum=None): return True @@ -125,8 +124,8 @@ class CreateAlarm(tables.LinkAction): ajax = True def get_link_url(self): - return urlresolvers.reverse(constants.URL_PREFIX + 'alarm_create', - args=(self.table.kwargs['service'],)) + return reverse(constants.URL_PREFIX + 'alarm_create', + args=(self.table.kwargs['service'],)) def allowed(self, request, datum=None): return True @@ -138,9 +137,8 @@ class EditAlarm(tables.LinkAction): classes = ("ajax-modal", "btn-create") def get_link_url(self, datum): - return urlresolvers.reverse(constants.URL_PREFIX + 'alarm_edit', - args=(self.table.kwargs['service'], - datum['id'], )) + return reverse(constants.URL_PREFIX + 'alarm_edit', + args=(self.table.kwargs['service'], datum['id'], )) def allowed(self, request, datum=None): return True @@ -191,7 +189,7 @@ class ShowAlarmDefinition(tables.LinkAction): def get_link_url(self, datum=None): url = 'horizon:monitoring:alarmdefs:alarm_detail' args = (datum['alarm_definition']['id'],) - return urlresolvers.reverse_lazy(url, args=args) + return reverse_lazy(url, args=args) class DeleteAlarm(tables.DeleteAction): @@ -230,8 +228,7 @@ class AlarmsFilterAction(tables.LinkAction): ajax = True def get_link_url(self): - return urlresolvers.reverse(constants.URL_PREFIX + 'alarm_filter', - args=()) + return reverse(constants.URL_PREFIX + 'alarm_filter', args=()) def allowed(self, request, datum=None): return True diff --git a/monitoring/alarms/tests.py b/monitoring/alarms/tests.py index 703591e0..39900273 100644 --- a/monitoring/alarms/tests.py +++ b/monitoring/alarms/tests.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from django.core import urlresolvers +from django.urls import reverse from mock import patch from monitoring.alarms import constants @@ -18,11 +18,11 @@ from monitoring.alarms import tables from monitoring.test import helpers -INDEX_URL = urlresolvers.reverse( +INDEX_URL = reverse( constants.URL_PREFIX + 'index') -ALARMS_URL_BY_DIMENSION = urlresolvers.reverse( +ALARMS_URL_BY_DIMENSION = reverse( constants.URL_PREFIX + 'alarm', args=('nova',)) -ALARMS_URL = urlresolvers.reverse( +ALARMS_URL = reverse( constants.URL_PREFIX + 'alarm', args=('all',)) diff --git a/monitoring/alarms/views.py b/monitoring/alarms/views.py index 86024004..b6e42318 100644 --- a/monitoring/alarms/views.py +++ b/monitoring/alarms/views.py @@ -20,9 +20,9 @@ from django.conf import settings from django.contrib import messages from django.core.paginator import EmptyPage from django.core.paginator import Paginator -from django.core.urlresolvers import reverse -from django.core.urlresolvers import reverse_lazy from django.shortcuts import redirect +from django.urls import reverse +from django.urls import reverse_lazy from django.utils.dateparse import parse_datetime from django.utils.translation import ugettext as _ # noqa from django.utils.translation import ugettext_lazy diff --git a/monitoring/notifications/tables.py b/monitoring/notifications/tables.py index 2ac1fde6..d52fdb42 100644 --- a/monitoring/notifications/tables.py +++ b/monitoring/notifications/tables.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from django.core import urlresolvers +from django.urls import reverse from django.utils.translation import ugettext_lazy as _ # noqa from django.utils.translation import ungettext_lazy @@ -66,7 +66,7 @@ class CreateNotification(tables.LinkAction): def get_link_url(self): url = constants.URL_PREFIX + 'notification_create' - return urlresolvers.reverse(url) + return reverse(url) def allowed(self, request, datum=None): return True @@ -78,8 +78,8 @@ class EditNotification(tables.LinkAction): classes = ("ajax-modal", "btn-create") def get_link_url(self, datum): - return urlresolvers.reverse(constants.URL_PREFIX + 'notification_edit', - args=(datum['id'], )) + return reverse(constants.URL_PREFIX + 'notification_edit', + args=(datum['id'], )) def allowed(self, request, datum=None): return True diff --git a/monitoring/notifications/tests.py b/monitoring/notifications/tests.py index fa8d2948..01076bae 100644 --- a/monitoring/notifications/tests.py +++ b/monitoring/notifications/tests.py @@ -10,18 +10,18 @@ # License for the specific language governing permissions and limitations # under the License. -from django.core import urlresolvers +from django.urls import reverse from mock import patch from monitoring.notifications import constants from monitoring.test import helpers -INDEX_URL = urlresolvers.reverse( +INDEX_URL = reverse( constants.URL_PREFIX + 'index') -CREATE_URL = urlresolvers.reverse( +CREATE_URL = reverse( constants.URL_PREFIX + 'notification_create') -EDIT_URL = urlresolvers.reverse( +EDIT_URL = reverse( constants.URL_PREFIX + 'notification_edit', args=('12345',)) diff --git a/monitoring/notifications/views.py b/monitoring/notifications/views.py index 75ac936e..a19d85cf 100644 --- a/monitoring/notifications/views.py +++ b/monitoring/notifications/views.py @@ -15,8 +15,8 @@ from django.contrib import messages from django.core.paginator import EmptyPage from django.core.paginator import Paginator -from django.core.urlresolvers import reverse -from django.core.urlresolvers import reverse_lazy +from django.urls import reverse +from django.urls import reverse_lazy from django.utils.translation import ugettext as _ # noqa from horizon import exceptions diff --git a/monitoring/overview/tests.py b/monitoring/overview/tests.py index 40c34f35..c127d4d2 100644 --- a/monitoring/overview/tests.py +++ b/monitoring/overview/tests.py @@ -12,15 +12,15 @@ # License for the specific language governing permissions and limitations # under the License. -from django.core import urlresolvers from django.test import RequestFactory +from django.urls import reverse from monitoring.overview import constants from monitoring.overview import views from monitoring.test import helpers -INDEX_URL = urlresolvers.reverse( +INDEX_URL = reverse( constants.URL_PREFIX + 'index') diff --git a/monitoring/overview/views.py b/monitoring/overview/views.py index 5972d9f2..d8d8542e 100644 --- a/monitoring/overview/views.py +++ b/monitoring/overview/views.py @@ -18,9 +18,9 @@ import json import logging from django.contrib import messages -from django.core.urlresolvers import reverse_lazy from django import http from django.http import HttpResponse +from django.urls import reverse_lazy from django.utils.translation import ugettext_lazy as _ # noqa from django.views.decorators.csrf import csrf_exempt from django.views import generic diff --git a/requirements.txt b/requirements.txt index de784c1c..80f33c14 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ # process, which may cause wedges in the gate later. oslo.log>=3.36.0 # Apache-2.0 python-monascaclient>=1.8.0 # Apache-2.0 -Django<2.0,>=1.11 # BSD +Django<2;python_version<'3.0' # BSD +Django<2.1;python_version>='3.0' # BSD horizon>=13.0.0 # Apache-2.0 six>=1.10.0 # MIT