Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Commit 500723a

Browse files
committed
Remove DRF 2.x compatibility functions and conditional definitions.
1 parent ab97ba5 commit 500723a

File tree

2 files changed

+12
-37
lines changed

2 files changed

+12
-37
lines changed

rest_framework_jwt/compat.py

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,22 @@
11
from django.contrib.auth import get_user_model
2-
from distutils.version import StrictVersion
32

4-
import rest_framework
53
from rest_framework import serializers
6-
from django.forms import widgets
74

85

9-
DRF_VERSION_INFO = StrictVersion(rest_framework.VERSION).version
10-
DRF2 = DRF_VERSION_INFO[0] == 2
11-
DRF3 = DRF_VERSION_INFO[0] == 3
6+
class Serializer(serializers.Serializer):
7+
@property
8+
def object(self):
9+
return self.validated_data
1210

1311

14-
if DRF2:
15-
class Serializer(serializers.Serializer):
16-
pass
12+
class PasswordField(serializers.CharField):
1713

18-
class PasswordField(serializers.CharField):
19-
widget = widgets.PasswordInput
20-
else:
21-
class Serializer(serializers.Serializer):
22-
@property
23-
def object(self):
24-
return self.validated_data
25-
26-
class PasswordField(serializers.CharField):
27-
28-
def __init__(self, *args, **kwargs):
29-
if 'style' not in kwargs:
30-
kwargs['style'] = {'input_type': 'password'}
31-
else:
32-
kwargs['style']['input_type'] = 'password'
33-
super(PasswordField, self).__init__(*args, **kwargs)
14+
def __init__(self, *args, **kwargs):
15+
if 'style' not in kwargs:
16+
kwargs['style'] = {'input_type': 'password'}
17+
else:
18+
kwargs['style']['input_type'] = 'password'
19+
super(PasswordField, self).__init__(*args, **kwargs)
3420

3521

3622
def get_username_field():
@@ -49,11 +35,3 @@ def get_username(user):
4935
username = user.username
5036

5137
return username
52-
53-
54-
def get_request_data(request):
55-
if DRF2:
56-
data = request.DATA
57-
else:
58-
data = request.data
59-
return data

rest_framework_jwt/views.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from rest_framework.response import Response
44

55
from .settings import api_settings
6-
from .compat import get_request_data
76
from .serializers import (
87
JSONWebTokenSerializer, RefreshJSONWebTokenSerializer,
98
VerifyJSONWebTokenSerializer
@@ -52,9 +51,7 @@ def get_serializer(self, *args, **kwargs):
5251
return serializer_class(*args, **kwargs)
5352

5453
def post(self, request, *args, **kwargs):
55-
serializer = self.get_serializer(
56-
data=get_request_data(request)
57-
)
54+
serializer = self.get_serializer(data=request.data)
5855

5956
if serializer.is_valid():
6057
user = serializer.object.get('user') or request.user

0 commit comments

Comments
 (0)