33
44from collections import OrderedDict
55import copy
6- import warnings
76
87from django .db .models .constants import LOOKUP_SEP
98from django .utils import six
1413from . import utils
1514
1615
17- def _base (f ):
18- f ._base = True
19- return f
20-
21-
22- def _get_fix_filter_field (cls ):
23- method = getattr (cls , 'fix_filter_field' )
24- if not getattr (method , '_base' , False ):
25- warnings .warn (
26- 'fix_filter_field is deprecated and no longer necessary. See: '
27- 'https://github.com/philipn/django-rest-framework-filters/issues/62' ,
28- DeprecationWarning , stacklevel = 2
29- )
30- return cls .fix_filter_field
31-
32-
3316class FilterSetMetaclass (filterset .FilterSetMetaclass ):
3417 def __new__ (cls , name , bases , attrs ):
3518 new_class = super (FilterSetMetaclass , cls ).__new__ (cls , name , bases , attrs )
36- fix_filter_field = _get_fix_filter_field (new_class )
3719 opts = copy .deepcopy (new_class ._meta )
3820
39- # order_by is not compatible.
40- if opts .order_by :
41- opts .order_by = False
42- warnings .warn (
43- 'order_by is no longer supported. Use '
44- 'rest_framework.filters.OrderingFilter instead. See: '
45- 'https://github.com/philipn/django-rest-framework-filters/issues/72' ,
46- DeprecationWarning , stacklevel = 2
47- )
48-
4921 # If no model is defined, skip all lookups processing
5022 if not opts .model :
5123 return new_class
@@ -76,12 +48,6 @@ def __new__(cls, name, bases, attrs):
7648
7749 # re-apply declared filters (sans `AllLookupsFilter`s)
7850 new_class .base_filters .update (declared_filters )
79-
80- # TODO: remove with deprecations
81- for name , filter_ in six .iteritems (new_class .base_filters .copy ()):
82- if name not in new_class .declared_filters :
83- new_class .base_filters [name ] = fix_filter_field (filter_ )
84-
8551 return new_class
8652
8753 @property
@@ -100,26 +66,6 @@ def related_filters(self):
10066class FilterSet (six .with_metaclass (FilterSetMetaclass , rest_framework .FilterSet )):
10167 _subset_cache = {}
10268
103- def __init__ (self , * args , ** kwargs ):
104- if 'cache' in kwargs :
105- warnings .warn (
106- "'cache' argument is deprecated. Override '_subset_cache' instead." ,
107- DeprecationWarning , stacklevel = 2
108- )
109- self .__class__ ._subset_cache = kwargs .pop ('cache' , None )
110-
111- super (FilterSet , self ).__init__ (* args , ** kwargs )
112-
113- for name , filter_ in six .iteritems (self .filters .copy ()):
114- if isinstance (filter_ , filters .RelatedFilter ):
115- # Add an 'isnull' filter to allow checking if the relation is empty.
116- filter_name = "%s%sisnull" % (filter_ .name , LOOKUP_SEP )
117- if filter_name not in self .filters :
118- self .filters [filter_name ] = filters .BooleanFilter (name = filter_ .name , lookup_expr = 'isnull' )
119-
120- elif isinstance (filter_ , filters .MethodFilter ):
121- filter_ .resolve_action ()
122-
12369 @classmethod
12470 def filters_for_model (cls , model , opts ):
12571 fields = opts .fields
@@ -131,14 +77,6 @@ def filters_for_model(cls, model, opts):
13177 fields = fields .copy ()
13278 for name , lookups in six .iteritems (fields ):
13379 if lookups == filters .ALL_LOOKUPS :
134- warnings .warn (
135- "ALL_LOOKUPS has been deprecated in favor of '__all__'. See: "
136- "https://github.com/philipn/django-rest-framework-filters/issues/62" ,
137- DeprecationWarning , stacklevel = 2
138- )
139- lookups = '__all__'
140-
141- if lookups == '__all__' :
14280 field = model ._meta .get_field (name )
14381 fields [name ] = utils .lookups_for_field (field )
14482
@@ -291,9 +229,9 @@ class FilterSubsetMetaclass(FilterSetMetaclass):
291229 def __new__ (cls , name , bases , attrs ):
292230 new_class = super (FilterSubsetMetaclass , cls ).__new__ (cls , name , bases , attrs )
293231 new_class .base_filters = OrderedDict ([
294- (name , f )
295- for name , f in six .iteritems (new_class .base_filters )
296- if name in filter_names
232+ (param , f )
233+ for param , f in six .iteritems (new_class .base_filters )
234+ if param in filter_names
297235 ])
298236 return new_class
299237
@@ -326,8 +264,3 @@ def qs(self):
326264 self .filters = available_filters
327265
328266 return qs
329-
330- @classmethod
331- @_base
332- def fix_filter_field (cls , f ):
333- return f
0 commit comments