Skip to content

Commit 6ace9de

Browse files
committed
Compatibility updates
+ removed some legacy code + added force_text for py3 support
1 parent 315f6f2 commit 6ace9de

File tree

6 files changed

+21
-30
lines changed

6 files changed

+21
-30
lines changed

demo/demo/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535
url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),
3636
url(r'^account/', include('allauth.urls')),
3737
url(r'^admin/', include(admin.site.urls)),
38-
url(r'^accounts/profile/$', RedirectView.as_view(url='/'), name='profile-redirect'),
38+
url(r'^accounts/profile/$', RedirectView.as_view(url='/', permanent=True), name='profile-redirect'),
3939
)

rest_auth/serializers.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
from django.contrib.auth import get_user_model, authenticate
22
from django.conf import settings
33
from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm
4-
try:
5-
from django.utils.http import urlsafe_base64_decode as uid_decoder
6-
except:
7-
# make compatible with django 1.5
8-
from django.utils.http import base36_to_int as uid_decoder
94
from django.contrib.auth.tokens import default_token_generator
5+
from django.utils.http import urlsafe_base64_decode as uid_decoder
106
from django.utils.translation import ugettext_lazy as _
11-
from django import VERSION
7+
from django.utils.encoding import force_text
128

139
from rest_framework import serializers, exceptions
1410
from rest_framework.authtoken.models import Token
1511
from rest_framework.exceptions import ValidationError
1612

13+
# Get the UserModel
14+
UserModel = get_user_model()
15+
1716

1817
class LoginSerializer(serializers.Serializer):
1918
username = serializers.CharField(required=False, allow_blank=True)
@@ -146,11 +145,10 @@ def custom_validation(self, attrs):
146145

147146
def validate(self, attrs):
148147
self._errors = {}
149-
# Get the UserModel
150-
UserModel = get_user_model()
148+
151149
# Decode the uidb64 to uid to get User object
152150
try:
153-
uid = uid_decoder(attrs['uid'])
151+
uid = force_text(uid_decoder(attrs['uid']))
154152
self.user = UserModel._default_manager.get(pk=uid)
155153
except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist):
156154
raise ValidationError({'uid': ['Invalid value']})
@@ -216,6 +214,6 @@ def validate(self, attrs):
216214

217215
def save(self):
218216
self.set_password_form.save()
219-
if VERSION[1] > 6 and not self.logout_on_password_change:
217+
if not self.logout_on_password_change:
220218
from django.contrib.auth import update_session_auth_hash
221219
update_session_auth_hash(self.request, self.user)

rest_auth/tests.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.core import mail
99
from django.test.utils import override_settings
1010
from django.contrib.sites.models import Site
11+
from django.utils.encoding import force_text
1112

1213
from allauth.socialaccount.models import SocialApp
1314
from allauth.socialaccount.providers.facebook.provider import GRAPH_API_URL
@@ -51,7 +52,7 @@ def send_request(self, request_method, *args, **kwargs):
5152
is_json = bool(
5253
[x for x in self.response._headers['content-type'] if 'json' in x])
5354
if is_json and self.response.content:
54-
self.response.json = json.loads(self.response.content)
55+
self.response.json = json.loads(force_text(self.response.content))
5556
else:
5657
self.response.json = {}
5758
if status_code:
@@ -298,7 +299,7 @@ def test_password_reset(self):
298299
data = {
299300
'new_password1': self.NEW_PASS,
300301
'new_password2': self.NEW_PASS,
301-
'uid': url_kwargs['uid'],
302+
'uid': force_text(url_kwargs['uid']),
302303
'token': '-wrong-token-'
303304
}
304305
self.post(url, data=data, status_code=400)
@@ -325,7 +326,7 @@ def test_password_reset(self):
325326
data = {
326327
'new_password1': self.NEW_PASS,
327328
'new_password2': self.NEW_PASS,
328-
'uid': url_kwargs['uid'],
329+
'uid': force_text(url_kwargs['uid']),
329330
'token': url_kwargs['token']
330331
}
331332
url = reverse('rest_password_reset_confirm')

rest_auth/utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
from six import string_types
2-
import sys
3-
if sys.version_info < (2, 7):
4-
from django.utils.importlib import import_module
5-
else:
6-
from importlib import import_module
2+
from importlib import import_module
73

84

95
def import_callable(path_or_callable):

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
keywords='django rest auth registration rest-framework django-registration api',
2929
zip_safe=False,
3030
install_requires=[
31-
'Django>=1.5.0',
32-
'djangorestframework>=3.0',
31+
'Django>=1.7.0',
32+
'djangorestframework>=3.1.0',
3333
'six>=1.9.0',
3434
],
3535
test_suite='runtests.runtests',

test_settings.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import django
21
import os
32
import sys
43

@@ -18,15 +17,12 @@
1817
IS_PROD = False
1918
IS_TEST = 'test' in sys.argv or 'test_coverage' in sys.argv
2019

21-
if django.VERSION[:2] >= (1, 3):
22-
DATABASES = {
23-
'default': {
24-
'ENGINE': 'django.db.backends.sqlite3',
25-
'NAME': ':memory:',
26-
}
20+
DATABASES = {
21+
'default': {
22+
'ENGINE': 'django.db.backends.sqlite3',
23+
'NAME': ':memory:',
2724
}
28-
else:
29-
DATABASE_ENGINE = 'sqlite3'
25+
}
3026

3127
MIDDLEWARE_CLASSES = [
3228
'django.middleware.common.CommonMiddleware',

0 commit comments

Comments
 (0)