1
1
from django .contrib .auth import get_user_model
2
- from distutils .version import StrictVersion
3
2
4
- import rest_framework
5
3
from rest_framework import serializers
6
- from django .forms import widgets
7
4
8
5
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
12
10
13
11
14
- if DRF2 :
15
- class Serializer (serializers .Serializer ):
16
- pass
12
+ class PasswordField (serializers .CharField ):
17
13
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 )
34
20
35
21
36
22
def get_username_field ():
@@ -49,11 +35,3 @@ def get_username(user):
49
35
username = user .username
50
36
51
37
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
0 commit comments