3
3
4
4
from collections import OrderedDict
5
5
import copy
6
- import warnings
7
6
8
7
from django .db .models .constants import LOOKUP_SEP
9
8
from django .utils import six
14
13
from . import utils
15
14
16
15
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
-
33
16
class FilterSetMetaclass (filterset .FilterSetMetaclass ):
34
17
def __new__ (cls , name , bases , attrs ):
35
18
new_class = super (FilterSetMetaclass , cls ).__new__ (cls , name , bases , attrs )
36
- fix_filter_field = _get_fix_filter_field (new_class )
37
19
opts = copy .deepcopy (new_class ._meta )
38
20
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
-
49
21
# If no model is defined, skip all lookups processing
50
22
if not opts .model :
51
23
return new_class
@@ -76,12 +48,6 @@ def __new__(cls, name, bases, attrs):
76
48
77
49
# re-apply declared filters (sans `AllLookupsFilter`s)
78
50
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
-
85
51
return new_class
86
52
87
53
@property
@@ -100,26 +66,6 @@ def related_filters(self):
100
66
class FilterSet (six .with_metaclass (FilterSetMetaclass , rest_framework .FilterSet )):
101
67
_subset_cache = {}
102
68
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
-
123
69
@classmethod
124
70
def filters_for_model (cls , model , opts ):
125
71
fields = opts .fields
@@ -131,14 +77,6 @@ def filters_for_model(cls, model, opts):
131
77
fields = fields .copy ()
132
78
for name , lookups in six .iteritems (fields ):
133
79
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__' :
142
80
field = model ._meta .get_field (name )
143
81
fields [name ] = utils .lookups_for_field (field )
144
82
@@ -291,9 +229,9 @@ class FilterSubsetMetaclass(FilterSetMetaclass):
291
229
def __new__ (cls , name , bases , attrs ):
292
230
new_class = super (FilterSubsetMetaclass , cls ).__new__ (cls , name , bases , attrs )
293
231
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
297
235
])
298
236
return new_class
299
237
@@ -326,8 +264,3 @@ def qs(self):
326
264
self .filters = available_filters
327
265
328
266
return qs
329
-
330
- @classmethod
331
- @_base
332
- def fix_filter_field (cls , f ):
333
- return f
0 commit comments