11from django .contrib .auth import get_user_model
2- from distutils .version import StrictVersion
32
4- import rest_framework
53from 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
3622def 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
0 commit comments