summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-08-18 16:38:02 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-08-18 16:38:49 +0200
commitde3ad8bb2d14ccf878121b96e6e0359dd8b1f9d5 (patch)
tree0e058217e43085d700a25fddc569dc1ed79b36a8
parenta120fac65a17137bc8ac710477478474e3f9973e (diff)
[py3] Avoided passing a lazy string to urlparse.
This causes an exception under Python 3. Fixed #18776.
-rw-r--r--django/contrib/auth/decorators.py5
-rw-r--r--django/contrib/auth/views.py7
2 files changed, 8 insertions, 4 deletions
diff --git a/django/contrib/auth/decorators.py b/django/contrib/auth/decorators.py
index 7a608d0777..beeb284998 100644
--- a/django/contrib/auth/decorators.py
+++ b/django/contrib/auth/decorators.py
@@ -7,6 +7,7 @@ from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.core.exceptions import PermissionDenied
from django.utils.decorators import available_attrs
+from django.utils.encoding import force_str
def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
@@ -22,9 +23,11 @@ def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIE
if test_func(request.user):
return view_func(request, *args, **kwargs)
path = request.build_absolute_uri()
+ # urlparse chokes on lazy objects in Python 3
+ login_url_as_str = force_str(login_url or settings.LOGIN_URL)
# If the login url is the same scheme and net location then just
# use the path as the "next" url.
- login_scheme, login_netloc = urlparse(login_url or settings.LOGIN_URL)[:2]
+ login_scheme, login_netloc = urlparse(login_url_as_str)[:2]
current_scheme, current_netloc = urlparse(path)[:2]
if ((not login_scheme or login_scheme == current_scheme) and
(not login_netloc or login_netloc == current_netloc)):
diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
index c30d6ec6d0..f93541b4bf 100644
--- a/django/contrib/auth/views.py
+++ b/django/contrib/auth/views.py
@@ -7,6 +7,7 @@ from django.conf import settings
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, QueryDict
from django.template.response import TemplateResponse
+from django.utils.encoding import force_str
from django.utils.http import base36_to_int
from django.utils.translation import ugettext as _
from django.views.decorators.debug import sensitive_post_parameters
@@ -116,10 +117,10 @@ def redirect_to_login(next, login_url=None,
"""
Redirects the user to the login page, passing the given 'next' page
"""
- if not login_url:
- login_url = settings.LOGIN_URL
+ # urlparse chokes on lazy objects in Python 3
+ login_url_as_str = force_str(login_url or settings.LOGIN_URL)
- login_url_parts = list(urlparse(login_url))
+ login_url_parts = list(urlparse(login_url_as_str))
if redirect_field_name:
querystring = QueryDict(login_url_parts[4], mutable=True)
querystring[redirect_field_name] = next