black on decorators.py
This commit is contained in:
parent
83ca957263
commit
3f155101af
1 changed files with 15 additions and 10 deletions
|
@ -10,17 +10,19 @@ from .models import Map
|
||||||
|
|
||||||
|
|
||||||
LOGIN_URL = getattr(settings, "LOGIN_URL", "login")
|
LOGIN_URL = getattr(settings, "LOGIN_URL", "login")
|
||||||
LOGIN_URL = (reverse_lazy(LOGIN_URL) if not LOGIN_URL.startswith("/")
|
LOGIN_URL = reverse_lazy(LOGIN_URL) if not LOGIN_URL.startswith("/") else LOGIN_URL
|
||||||
else LOGIN_URL)
|
|
||||||
|
|
||||||
|
|
||||||
def login_required_if_not_anonymous_allowed(view_func):
|
def login_required_if_not_anonymous_allowed(view_func):
|
||||||
@wraps(view_func)
|
@wraps(view_func)
|
||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
if (not getattr(settings, "UMAP_ALLOW_ANONYMOUS", False)
|
if (
|
||||||
and not request.user.is_authenticated):
|
not getattr(settings, "UMAP_ALLOW_ANONYMOUS", False)
|
||||||
|
and not request.user.is_authenticated
|
||||||
|
):
|
||||||
return simple_json_response(login_required=str(LOGIN_URL))
|
return simple_json_response(login_required=str(LOGIN_URL))
|
||||||
return view_func(request, *args, **kwargs)
|
return view_func(request, *args, **kwargs)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,11 +30,12 @@ def map_permissions_check(view_func):
|
||||||
"""
|
"""
|
||||||
Used for URLs dealing with the map.
|
Used for URLs dealing with the map.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@wraps(view_func)
|
@wraps(view_func)
|
||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
map_inst = get_object_or_404(Map, pk=kwargs['map_id'])
|
map_inst = get_object_or_404(Map, pk=kwargs["map_id"])
|
||||||
user = request.user
|
user = request.user
|
||||||
kwargs['map_inst'] = map_inst # Avoid rerequesting the map in the view
|
kwargs["map_inst"] = map_inst # Avoid rerequesting the map in the view
|
||||||
if map_inst.edit_status >= map_inst.EDITORS:
|
if map_inst.edit_status >= map_inst.EDITORS:
|
||||||
can_edit = map_inst.can_edit(user=user, request=request)
|
can_edit = map_inst.can_edit(user=user, request=request)
|
||||||
if not can_edit:
|
if not can_edit:
|
||||||
|
@ -40,6 +43,7 @@ def map_permissions_check(view_func):
|
||||||
return simple_json_response(login_required=str(LOGIN_URL))
|
return simple_json_response(login_required=str(LOGIN_URL))
|
||||||
return HttpResponseForbidden()
|
return HttpResponseForbidden()
|
||||||
return view_func(request, *args, **kwargs)
|
return view_func(request, *args, **kwargs)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,9 +52,10 @@ def jsonize_view(view_func):
|
||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
response = view_func(request, *args, **kwargs)
|
response = view_func(request, *args, **kwargs)
|
||||||
response_kwargs = {}
|
response_kwargs = {}
|
||||||
if hasattr(response, 'rendered_content'):
|
if hasattr(response, "rendered_content"):
|
||||||
response_kwargs['html'] = response.rendered_content
|
response_kwargs["html"] = response.rendered_content
|
||||||
if response.has_header('location'):
|
if response.has_header("location"):
|
||||||
response_kwargs['redirect'] = response['location']
|
response_kwargs["redirect"] = response["location"]
|
||||||
return simple_json_response(**response_kwargs)
|
return simple_json_response(**response_kwargs)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
Loading…
Reference in a new issue