22
33from bson import DBRef , ObjectId
44from bson .errors import InvalidId
5- from django .utils import six
6- from django .utils .encoding import smart_text
7- from django .utils .translation import ugettext_lazy as _
8- from mongoengine import fields as me_fields
5+ from django .utils .encoding import smart_str
6+ from django .utils .translation import gettext_lazy as _
97from mongoengine import Document , EmbeddedDocument
8+ from mongoengine import fields as me_fields
109from mongoengine .base import get_document
1110from mongoengine .base .common import _document_registry
12- from mongoengine .errors import ValidationError as MongoValidationError
1311from mongoengine .errors import DoesNotExist , NotRegistered
12+ from mongoengine .errors import ValidationError as MongoValidationError
1413from mongoengine .queryset import QuerySet , QuerySetManager
1514from rest_framework import serializers
1615from rest_framework .exceptions import ValidationError
17- from rest_framework .fields import empty , html
16+ from rest_framework .fields import empty
17+ from rest_framework .utils import html
1818from rest_framework .settings import api_settings
1919
2020
@@ -23,12 +23,12 @@ class ObjectIdField(serializers.Field):
2323
2424 def to_internal_value (self , value ):
2525 try :
26- return ObjectId (smart_text (value ))
26+ return ObjectId (smart_str (value ))
2727 except InvalidId :
2828 raise serializers .ValidationError ("'%s' is not a valid ObjectId" % value )
2929
3030 def to_representation (self , value ):
31- return smart_text (value )
31+ return smart_str (value )
3232
3333
3434class DocumentField (serializers .Field ):
@@ -60,13 +60,13 @@ def to_representation(self, obj):
6060
6161 DRF ModelField uses ``value_to_string`` for this purpose. Mongoengine fields do not have such method.
6262
63- This implementation uses ``django.utils.encoding.smart_text `` to convert everything to text, while keeping json-safe types intact.
63+ This implementation uses ``django.utils.encoding.smart_str `` to convert everything to text, while keeping json-safe types intact.
6464
6565 NB: The argument is whole object, instead of attribute value. This is upstream feature.
6666 Probably because the field can be represented by a complicated method with nontrivial way to extract data.
6767 """
6868 value = self .model_field .__get__ (obj , None )
69- return smart_text (value , strings_only = True )
69+ return smart_str (value , strings_only = True )
7070
7171 def run_validators (self , value ):
7272 """ validate value.
@@ -121,7 +121,7 @@ class GenericField(serializers.Field):
121121 """ Field for generic values.
122122
123123 Recursively traverses lists and dicts.
124- Primitive values are serialized using ``django.utils.encoding.smart_text `` (keeping json-safe intact).
124+ Primitive values are serialized using ``django.utils.encoding.smart_str `` (keeping json-safe intact).
125125 Embedded documents handled using temporary GenericEmbeddedField.
126126
127127 No validation performed.
@@ -143,7 +143,7 @@ def represent_data(self, data):
143143 elif data is None :
144144 return None
145145 else :
146- return smart_text (data , strings_only = True )
146+ return smart_str (data , strings_only = True )
147147
148148 def to_internal_value (self , value ):
149149 return self .parse_data (value )
@@ -250,7 +250,7 @@ def choices(self):
250250
251251 return OrderedDict ([
252252 (
253- six . text_type (self .to_representation (item )),
253+ str (self .to_representation (item )),
254254 self .display_value (item )
255255 )
256256 for item in queryset
@@ -261,7 +261,7 @@ def grouped_choices(self):
261261 return self .choices
262262
263263 def display_value (self , instance ):
264- return six . text_type (instance )
264+ return str (instance )
265265
266266 def parse_id (self , value ):
267267 try :
@@ -529,7 +529,7 @@ def to_internal_value(self, data):
529529 api_settings .NON_FIELD_ERRORS_KEY : [message ]
530530 })
531531 return {
532- six . text_type (key ): self .child .run_validation (value )
532+ str (key ): self .child .run_validation (value )
533533 for key , value in data .items ()
534534 }
535535
@@ -547,7 +547,7 @@ class FileField(serializers.FileField):
547547 """
548548
549549 def to_representation (self , value ):
550- return smart_text (value .grid_id ) if hasattr (value , 'grid_id' ) else None
550+ return smart_str (value .grid_id ) if hasattr (value , 'grid_id' ) else None
551551
552552
553553class ImageField (FileField ):
0 commit comments