Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

[py3] fixed __proxy__.decode doesn't exists #281

Closed
wants to merge 1 commit into from

2 participants

Natim Aymeric Augustin
Natim

fixed proxy.decode doesn't exists on django/contrib/auth/decorators.py

Aymeric Augustin aaugustin closed this August 17, 2012
Aymeric Augustin
Owner

GitHub seems to have lost my comment :( Here is it again.

I'd prefer to fix the root cause rather than this specific symptom, as explained in this ticket:
https://code.djangoproject.com/ticket/18776
The conditional on six.PY3 is needlessly complex, six.text_type just does the job.

If we chose this path, in fact, we'd probably just slap force_text around login_url.

Natim

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Aug 17, 2012
Natim [py3] fixed __proxy__.decode doesn't exists on django/contrib/auth/de…
…corators.py
22987dd
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 9 additions and 2 deletions. Show diff stats Hide diff stats

  1. 11  django/contrib/auth/decorators.py
11  django/contrib/auth/decorators.py
@@ -7,6 +7,7 @@
7 7
 from django.contrib.auth import REDIRECT_FIELD_NAME
8 8
 from django.core.exceptions import PermissionDenied
9 9
 from django.utils.decorators import available_attrs
  10
+from django.utils import six
10 11
 
11 12
 
12 13
 def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
@@ -22,15 +23,21 @@ def _wrapped_view(request, *args, **kwargs):
22 23
             if test_func(request.user):
23 24
                 return view_func(request, *args, **kwargs)
24 25
             path = request.build_absolute_uri()
  26
+            _login_url = None
  27
+            if login_url is not None:
  28
+                if six.PY3:
  29
+                    _login_url = str(login_url)
  30
+                else:
  31
+                    _login_url = unicode(login_url)
25 32
             # If the login url is the same scheme and net location then just
26 33
             # use the path as the "next" url.
27  
-            login_scheme, login_netloc = urlparse(login_url or settings.LOGIN_URL)[:2]
  34
+            login_scheme, login_netloc = urlparse(_login_url or settings.LOGIN_URL)[:2]
28 35
             current_scheme, current_netloc = urlparse(path)[:2]
29 36
             if ((not login_scheme or login_scheme == current_scheme) and
30 37
                 (not login_netloc or login_netloc == current_netloc)):
31 38
                 path = request.get_full_path()
32 39
             from django.contrib.auth.views import redirect_to_login
33  
-            return redirect_to_login(path, login_url, redirect_field_name)
  40
+            return redirect_to_login(path, _login_url, redirect_field_name)
34 41
         return _wrapped_view
35 42
     return decorator
36 43
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.