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
This commit is contained in:
parent
420eaa5bac
commit
6dfcb90131
@ -21,13 +21,12 @@ General-purpose decorators for use with Horizon.
|
|||||||
"""
|
"""
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
from django.utils.decorators import available_attrs
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
def _current_component(view_func, dashboard=None, panel=None):
|
def _current_component(view_func, dashboard=None, panel=None):
|
||||||
"""Sets the currently-active dashboard and/or panel on the request."""
|
"""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):
|
def dec(request, *args, **kwargs):
|
||||||
if dashboard:
|
if dashboard:
|
||||||
request.horizon['dashboard'] = dashboard
|
request.horizon['dashboard'] = dashboard
|
||||||
@ -46,7 +45,7 @@ def require_auth(view_func):
|
|||||||
"""
|
"""
|
||||||
from horizon.exceptions import NotAuthenticated
|
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):
|
def dec(request, *args, **kwargs):
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
return view_func(request, *args, **kwargs)
|
return view_func(request, *args, **kwargs)
|
||||||
@ -77,7 +76,7 @@ def require_perms(view_func, required):
|
|||||||
current_perms = getattr(view_func, '_required_perms', set([]))
|
current_perms = getattr(view_func, '_required_perms', set([]))
|
||||||
view_func._required_perms = current_perms | set(required)
|
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):
|
def dec(request, *args, **kwargs):
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
if request.user.has_perms(view_func._required_perms):
|
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
|
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):
|
def dec(request, *args, **kwargs):
|
||||||
if not component.can_access({'request': request}):
|
if not component.can_access({'request': request}):
|
||||||
raise NotAuthorized(_("You are not authorized to access %s")
|
raise NotAuthorized(_("You are not authorized to access %s")
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import datetime
|
import datetime
|
||||||
|
import functools
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -22,7 +23,6 @@ from django import http as django_http
|
|||||||
from django.middleware import csrf
|
from django.middleware import csrf
|
||||||
from django import shortcuts
|
from django import shortcuts
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import functional
|
|
||||||
from django.utils import http
|
from django.utils import http
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.views.decorators.cache import never_cache
|
from django.views.decorators.cache import never_cache
|
||||||
@ -116,9 +116,9 @@ def login(request):
|
|||||||
initial.update({'region': requested_region})
|
initial.update({'region': requested_region})
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = functional.curry(forms.Login)
|
form = functools.partial(forms.Login)
|
||||||
else:
|
else:
|
||||||
form = functional.curry(forms.Login, initial=initial)
|
form = functools.partial(forms.Login, initial=initial)
|
||||||
|
|
||||||
choices = settings.WEBSSO_CHOICES
|
choices = settings.WEBSSO_CHOICES
|
||||||
reason = get_csrf_reason(request.GET.get('csrf_failure'))
|
reason = get_csrf_reason(request.GET.get('csrf_failure'))
|
||||||
|
@ -17,7 +17,6 @@ import logging
|
|||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django import http
|
from django import http
|
||||||
from django.utils import decorators
|
|
||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
@ -104,7 +103,7 @@ def ajax(authenticated=True, data_required=False,
|
|||||||
def decorator(function, authenticated=authenticated,
|
def decorator(function, authenticated=authenticated,
|
||||||
data_required=data_required):
|
data_required=data_required):
|
||||||
@functools.wraps(function,
|
@functools.wraps(function,
|
||||||
assigned=decorators.available_attrs(function))
|
assigned=functools.WRAPPER_ASSIGNMENTS)
|
||||||
def _wrapped(self, request, *args, **kw):
|
def _wrapped(self, request, *args, **kw):
|
||||||
if authenticated and not request.user.is_authenticated:
|
if authenticated and not request.user.is_authenticated:
|
||||||
return JSONResponse('not logged in', 401)
|
return JSONResponse('not logged in', 401)
|
||||||
|
Loading…
Reference in New Issue
Block a user