Skip to content

Commit 8dfcf8c

Browse files
author
Ryan P Kilby
committed
Remove 1.0 deprecations
1 parent 4cf4ee9 commit 8dfcf8c

File tree

4 files changed

+5
-366
lines changed

4 files changed

+5
-366
lines changed

rest_framework_filters/fields.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

rest_framework_filters/filters.py

Lines changed: 2 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
from __future__ import absolute_import
22
from __future__ import unicode_literals
33

4-
import warnings
54
from django.utils import six
65

76
from django_filters.rest_framework.filters import *
87

9-
from . import fields
108

11-
12-
class ALL_LOOKUPS(object):
13-
pass
9+
ALL_LOOKUPS = '__all__'
1410

1511

1612
def _import_class(path):
@@ -46,81 +42,4 @@ def field(self):
4642

4743

4844
class AllLookupsFilter(Filter):
49-
lookups = '__all__'
50-
51-
52-
###################################################
53-
# Fixed-up versions of some of the default filters
54-
###################################################
55-
56-
class InSetNumberFilter(Filter):
57-
field_class = fields.ArrayDecimalField
58-
59-
def __init__(self, *args, **kwargs):
60-
super(InSetNumberFilter, self).__init__(*args, **kwargs)
61-
warnings.warn(
62-
'InSetNumberFilter is deprecated and no longer necessary. See: '
63-
'https://github.com/philipn/django-rest-framework-filters/issues/62',
64-
DeprecationWarning, stacklevel=2
65-
)
66-
67-
68-
class InSetCharFilter(Filter):
69-
field_class = fields.ArrayCharField
70-
71-
def __init__(self, *args, **kwargs):
72-
super(InSetCharFilter, self).__init__(*args, **kwargs)
73-
warnings.warn(
74-
'InSetCharFilter is deprecated and no longer necessary. See: '
75-
'https://github.com/philipn/django-rest-framework-filters/issues/62',
76-
DeprecationWarning, stacklevel=2
77-
)
78-
79-
80-
class MethodFilter(Filter):
81-
"""
82-
This filter will allow you to run a method that exists on the filterset class
83-
"""
84-
85-
def __init__(self, *args, **kwargs):
86-
self.action = kwargs.pop('action', '')
87-
super(MethodFilter, self).__init__(*args, **kwargs)
88-
warnings.warn(
89-
'MethodFilter is deprecated and no longer necessary. See: '
90-
'https://github.com/philipn/django-rest-framework-filters/issues/109',
91-
DeprecationWarning, stacklevel=2
92-
)
93-
94-
def resolve_action(self):
95-
"""
96-
This method provides a hook for the parent FilterSet to resolve the filter's
97-
action after initialization. This is necessary, as the filter name may change
98-
as it's expanded across related filtersets.
99-
100-
ie, `is_published` might become `post__is_published`.
101-
"""
102-
# noop if a function was provided as the action
103-
if callable(self.action):
104-
return
105-
106-
# otherwise, action is a string representing an action to be called on
107-
# the parent FilterSet.
108-
parent_action = self.action or 'filter_{0}'.format(self.name)
109-
110-
parent = getattr(self, 'parent', None)
111-
self.action = getattr(parent, parent_action, None)
112-
113-
assert callable(self.action), (
114-
'Expected parent FilterSet `%s.%s` to have a `.%s()` method.' %
115-
(parent.__class__.__module__, parent.__class__.__name__, parent_action)
116-
)
117-
118-
def filter(self, qs, value):
119-
"""
120-
This filter method will act as a proxy for the actual method we want to
121-
call.
122-
It will try to find the method on the parent filterset,
123-
if not it attempts to search for the method `field_{{attribute_name}}`.
124-
Otherwise it defaults to just returning the queryset.
125-
"""
126-
return self.action(self.name, qs, value)
45+
lookups = ALL_LOOKUPS

rest_framework_filters/filterset.py

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from collections import OrderedDict
55
import copy
6-
import warnings
76

87
from django.db.models.constants import LOOKUP_SEP
98
from django.utils import six
@@ -14,38 +13,11 @@
1413
from . 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-
3316
class 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):
10066
class 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

Comments
 (0)