From 6dfcb901314476df95028bdc7aa536809fb1d127 Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Wed, 24 Feb 2021 21:16:30 +0900 Subject: [PATCH] Support Django 3.0 and 3.1 support (1) * Django 3.0 dropped django.utils.decorators.available_attrs() in favor of functools.WRAPPER_ASSIGNMENTS. * Django 3.0 dropped django.utils.functional.curry() in favor of functools.partial() or functools.partialmethod(). https://docs.djangoproject.com/en/3.1/releases/3.0/#removed-private-python-2-compatibility-apis Change-Id: I4ab0e720a8ffe13a08f5e607a59e39f252338b90 --- horizon/decorators.py | 9 ++++----- openstack_auth/views.py | 6 +++--- openstack_dashboard/api/rest/utils.py | 3 +-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/horizon/decorators.py b/horizon/decorators.py index fa67761b85..38cca3f21e 100644 --- a/horizon/decorators.py +++ b/horizon/decorators.py @@ -21,13 +21,12 @@ General-purpose decorators for use with Horizon. """ import functools -from django.utils.decorators import available_attrs from django.utils.translation import ugettext_lazy as _ def _current_component(view_func, dashboard=None, panel=None): """Sets the currently-active dashboard and/or panel on the request.""" - @functools.wraps(view_func, assigned=available_attrs(view_func)) + @functools.wraps(view_func, assigned=functools.WRAPPER_ASSIGNMENTS) def dec(request, *args, **kwargs): if dashboard: request.horizon['dashboard'] = dashboard @@ -46,7 +45,7 @@ def require_auth(view_func): """ from horizon.exceptions import NotAuthenticated - @functools.wraps(view_func, assigned=available_attrs(view_func)) + @functools.wraps(view_func, assigned=functools.WRAPPER_ASSIGNMENTS) def dec(request, *args, **kwargs): if request.user.is_authenticated: return view_func(request, *args, **kwargs) @@ -77,7 +76,7 @@ def require_perms(view_func, required): current_perms = getattr(view_func, '_required_perms', set([])) view_func._required_perms = current_perms | set(required) - @functools.wraps(view_func, assigned=available_attrs(view_func)) + @functools.wraps(view_func, assigned=functools.WRAPPER_ASSIGNMENTS) def dec(request, *args, **kwargs): if request.user.is_authenticated: if request.user.has_perms(view_func._required_perms): @@ -103,7 +102,7 @@ def require_component_access(view_func, component): """ from horizon.exceptions import NotAuthorized - @functools.wraps(view_func, assigned=available_attrs(view_func)) + @functools.wraps(view_func, assigned=functools.WRAPPER_ASSIGNMENTS) def dec(request, *args, **kwargs): if not component.can_access({'request': request}): raise NotAuthorized(_("You are not authorized to access %s") diff --git a/openstack_auth/views.py b/openstack_auth/views.py index 353dc99157..bc2394668a 100644 --- a/openstack_auth/views.py +++ b/openstack_auth/views.py @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import datetime +import functools import logging from django.conf import settings @@ -22,7 +23,6 @@ from django import http as django_http from django.middleware import csrf from django import shortcuts from django.urls import reverse -from django.utils import functional from django.utils import http from django.utils.translation import ugettext_lazy as _ from django.views.decorators.cache import never_cache @@ -116,9 +116,9 @@ def login(request): initial.update({'region': requested_region}) if request.method == "POST": - form = functional.curry(forms.Login) + form = functools.partial(forms.Login) else: - form = functional.curry(forms.Login, initial=initial) + form = functools.partial(forms.Login, initial=initial) choices = settings.WEBSSO_CHOICES reason = get_csrf_reason(request.GET.get('csrf_failure')) diff --git a/openstack_dashboard/api/rest/utils.py b/openstack_dashboard/api/rest/utils.py index a9bc3ea55c..8073ffa4a0 100644 --- a/openstack_dashboard/api/rest/utils.py +++ b/openstack_dashboard/api/rest/utils.py @@ -17,7 +17,6 @@ import logging from django.conf import settings from django import http -from django.utils import decorators from oslo_serialization import jsonutils @@ -104,7 +103,7 @@ def ajax(authenticated=True, data_required=False, def decorator(function, authenticated=authenticated, data_required=data_required): @functools.wraps(function, - assigned=decorators.available_attrs(function)) + assigned=functools.WRAPPER_ASSIGNMENTS) def _wrapped(self, request, *args, **kw): if authenticated and not request.user.is_authenticated: return JSONResponse('not logged in', 401)