Yohan Boniface avatar Yohan Boniface committed 418efe9

Do not reverse LOGIN_URL if it's already an URL (fix #72)

Comments (0)

Files changed (1)

leaflet_storage/decorators.py

 from functools import wraps
 
-from django.core.urlresolvers import reverse
+from django.core.urlresolvers import reverse_lazy
 from django.shortcuts import get_object_or_404
 from django.http import HttpResponseForbidden
 from django.conf import settings
 from .models import Map
 
 
-LOGIN_URL_NAME = getattr(settings, "LOGIN_URL", "login")
+LOGIN_URL = getattr(settings, "LOGIN_URL", "login")
+LOGIN_URL = reverse_lazy(LOGIN_URL) if not LOGIN_URL.startswith("/") else LOGIN_URL
 
 
 def login_required_if_not_anonymous_allowed(view_func):
     def wrapper(request, *args, **kwargs):
         if (not getattr(settings, "LEAFLET_STORAGE_ALLOW_ANONYMOUS", False)
                 and not request.user.is_authenticated()):
-            return simple_json_response(login_required=reverse(LOGIN_URL_NAME))
+            return simple_json_response(login_required=str(LOGIN_URL))
         return view_func(request, *args, **kwargs)
     return wrapper
 
             can_edit = map_inst.can_edit(user=user, request=request)
             if not can_edit:
                 if not user.is_authenticated():
-                    return simple_json_response(login_required=reverse(LOGIN_URL_NAME))
+                    return simple_json_response(login_required=str(LOGIN_URL))
                 else:
                     return HttpResponseForbidden('Action not allowed for user.')
         return view_func(request, *args, **kwargs)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.