1- # -*- coding: utf-8 -*-
2-
3- from __future__ import absolute_import , unicode_literals
4-
51import copy
62import six
73import warnings
@@ -46,7 +42,7 @@ class Meta(type):
4642 index_aliases = {}
4743
4844 def __new__ (mcs , name , bases , attrs ):
49- cls = super (Meta , mcs ).__new__ (mcs , str (name ), bases , attrs )
45+ cls = super ().__new__ (mcs , str (name ), bases , attrs )
5046
5147 if cls .fields and cls .exclude :
5248 raise ImproperlyConfigured ("%s cannot define both 'fields' and 'exclude'." % name )
@@ -69,7 +65,7 @@ class HaystackSerializerMeta(serializers.SerializerMetaclass):
6965 def __new__ (mcs , name , bases , attrs ):
7066 attrs .setdefault ("_abstract" , False )
7167
72- cls = super (HaystackSerializerMeta , mcs ).__new__ (mcs , str (name ), bases , attrs )
68+ cls = super ().__new__ (mcs , str (name ), bases , attrs )
7369
7470 if getattr (cls , "Meta" , None ):
7571 cls .Meta = Meta ("Meta" , (Meta ,), dict (cls .Meta .__dict__ ))
@@ -80,7 +76,7 @@ def __new__(mcs, name, bases, attrs):
8076 return cls
8177
8278
83- class HaystackSerializer (six . with_metaclass ( HaystackSerializerMeta , serializers .Serializer ) ):
79+ class HaystackSerializer (serializers .Serializer , metaclass = HaystackSerializerMeta ):
8480 """
8581 A `HaystackSerializer` which populates fields based on
8682 which models that are available in the SearchQueryset.
@@ -111,7 +107,7 @@ class HaystackSerializer(six.with_metaclass(HaystackSerializerMeta, serializers.
111107 })
112108
113109 def __init__ (self , instance = None , data = empty , ** kwargs ):
114- super (HaystackSerializer , self ).__init__ (instance , data , ** kwargs )
110+ super ().__init__ (instance , data , ** kwargs )
115111
116112 if not self .Meta .index_classes and not self .Meta .serializers :
117113 raise ImproperlyConfigured ("You must set either the 'index_classes' or 'serializers' "
@@ -183,9 +179,9 @@ def get_fields(self):
183179 prefix = ""
184180 if prefix_field_names :
185181 prefix = "_%s__" % self ._get_index_class_name (index_cls )
186- for field_name , field_type in six . iteritems ( index_cls .fields ):
182+ for field_name , field_type in index_cls .fields . items ( ):
187183 orig_name = field_name
188- field_name = "%s%s" % ( prefix , field_name )
184+ field_name = f" { prefix } { field_name } "
189185
190186 # Don't use this field if it is in `ignore_fields`
191187 if orig_name in ignore_fields or field_name in ignore_fields :
@@ -223,7 +219,7 @@ def to_representation(self, instance):
223219 if self .Meta .serializers :
224220 ret = self .multi_serializer_representation (instance )
225221 else :
226- ret = super (HaystackSerializer , self ).to_representation (instance )
222+ ret = super ().to_representation (instance )
227223 prefix_field_names = len (getattr (self .Meta , "index_classes" )) > 1
228224 current_index = self ._get_index_class_name (type (instance .searchindex ))
229225 for field in self .fields .keys ():
@@ -264,7 +260,7 @@ class FacetFieldSerializer(serializers.Serializer):
264260
265261 def __init__ (self , * args , ** kwargs ):
266262 self ._parent_field = None
267- super (FacetFieldSerializer , self ).__init__ (* args , ** kwargs )
263+ super ().__init__ (* args , ** kwargs )
268264
269265 @property
270266 def parent_field (self ):
@@ -317,7 +313,7 @@ def get_text(self, instance):
317313 The text field should contain the faceted value.
318314 """
319315 instance = instance [0 ]
320- if isinstance (instance , (six . text_type , six . string_types )):
316+ if isinstance (instance , (str , ( str ,) )):
321317 return serializers .CharField (read_only = True ).to_representation (instance )
322318 elif isinstance (instance , datetime ):
323319 return serializers .DateTimeField (read_only = True ).to_representation (instance )
@@ -346,10 +342,10 @@ def get_narrow_url(self, instance):
346342 del query_params [page_query_param ]
347343
348344 selected_facets = set (query_params .pop (self .root .facet_query_params_text , []))
349- selected_facets .add ("%(field)s_exact:%(text)s" % { "field" : self .parent_field , "text" : text })
345+ selected_facets .add (f" { self .parent_field } _exact: { text } " )
350346 query_params .setlist (self .root .facet_query_params_text , sorted (selected_facets ))
351347
352- path = "%(path)s?%(query)s" % { "path" : request .path_info , "query" : query_params .urlencode ()}
348+ path = f" { request .path_info } ? { query_params .urlencode ()} "
353349 url = request .build_absolute_uri (path )
354350 return serializers .Hyperlink (url , "narrow-url" )
355351
@@ -359,10 +355,10 @@ def to_representation(self, field, instance):
359355 so that each field can query it to see what kind of attribute they are processing.
360356 """
361357 self .parent_field = field
362- return super (FacetFieldSerializer , self ).to_representation (instance )
358+ return super ().to_representation (instance )
363359
364360
365- class HaystackFacetSerializer (six . with_metaclass ( HaystackSerializerMeta , serializers .Serializer ) ):
361+ class HaystackFacetSerializer (serializers .Serializer , metaclass = HaystackSerializerMeta ):
366362 """
367363 The ``HaystackFacetSerializer`` is used to serialize the ``facet_counts()``
368364 dictionary results on a ``SearchQuerySet`` instance.
@@ -426,7 +422,7 @@ def facet_query_params_text(self):
426422 return self .context ["facet_query_params_text" ]
427423
428424
429- class HaystackSerializerMixin ( object ) :
425+ class HaystackSerializerMixin :
430426 """
431427 This mixin can be added to a serializer to use the actual object as the data source for serialization rather
432428 than the data stored in the search index fields. This makes it easy to return data from search results in
@@ -435,10 +431,10 @@ class HaystackSerializerMixin(object):
435431
436432 def to_representation (self , instance ):
437433 obj = instance .object
438- return super (HaystackSerializerMixin , self ).to_representation (obj )
434+ return super ().to_representation (obj )
439435
440436
441- class HighlighterMixin ( object ) :
437+ class HighlighterMixin :
442438 """
443439 This mixin adds support for ``highlighting`` (the pure python, portable
444440 version, not SearchQuerySet().highlight()). See Haystack docs
@@ -474,11 +470,11 @@ def get_terms(self, data):
474470 """
475471 Returns the terms to be highlighted
476472 """
477- terms = " " .join (six . itervalues ( self .context ["request" ].GET ))
473+ terms = " " .join (self .context ["request" ].GET . values ( ))
478474 return terms
479475
480476 def to_representation (self , instance ):
481- ret = super (HighlighterMixin , self ).to_representation (instance )
477+ ret = super ().to_representation (instance )
482478 terms = self .get_terms (ret )
483479 if terms :
484480 highlighter = self .get_highlighter ()(terms , ** {
0 commit comments