Skip to content

Remove 0.10 deprecations #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions rest_framework_filters/fields.py

This file was deleted.

85 changes: 2 additions & 83 deletions rest_framework_filters/filters.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import warnings
from django.utils import six

from django_filters.rest_framework.filters import *

from . import fields


class ALL_LOOKUPS(object):
pass
ALL_LOOKUPS = '__all__'


def _import_class(path):
Expand Down Expand Up @@ -46,81 +42,4 @@ def field(self):


class AllLookupsFilter(Filter):
lookups = '__all__'


###################################################
# Fixed-up versions of some of the default filters
###################################################

class InSetNumberFilter(Filter):
field_class = fields.ArrayDecimalField

def __init__(self, *args, **kwargs):
super(InSetNumberFilter, self).__init__(*args, **kwargs)
warnings.warn(
'InSetNumberFilter is deprecated and no longer necessary. See: '
'https://github.com/philipn/django-rest-framework-filters/issues/62',
DeprecationWarning, stacklevel=2
)


class InSetCharFilter(Filter):
field_class = fields.ArrayCharField

def __init__(self, *args, **kwargs):
super(InSetCharFilter, self).__init__(*args, **kwargs)
warnings.warn(
'InSetCharFilter is deprecated and no longer necessary. See: '
'https://github.com/philipn/django-rest-framework-filters/issues/62',
DeprecationWarning, stacklevel=2
)


class MethodFilter(Filter):
"""
This filter will allow you to run a method that exists on the filterset class
"""

def __init__(self, *args, **kwargs):
self.action = kwargs.pop('action', '')
super(MethodFilter, self).__init__(*args, **kwargs)
warnings.warn(
'MethodFilter is deprecated and no longer necessary. See: '
'https://github.com/philipn/django-rest-framework-filters/issues/109',
DeprecationWarning, stacklevel=2
)

def resolve_action(self):
"""
This method provides a hook for the parent FilterSet to resolve the filter's
action after initialization. This is necessary, as the filter name may change
as it's expanded across related filtersets.

ie, `is_published` might become `post__is_published`.
"""
# noop if a function was provided as the action
if callable(self.action):
return

# otherwise, action is a string representing an action to be called on
# the parent FilterSet.
parent_action = self.action or 'filter_{0}'.format(self.name)

parent = getattr(self, 'parent', None)
self.action = getattr(parent, parent_action, None)

assert callable(self.action), (
'Expected parent FilterSet `%s.%s` to have a `.%s()` method.' %
(parent.__class__.__module__, parent.__class__.__name__, parent_action)
)

def filter(self, qs, value):
"""
This filter method will act as a proxy for the actual method we want to
call.
It will try to find the method on the parent filterset,
if not it attempts to search for the method `field_{{attribute_name}}`.
Otherwise it defaults to just returning the queryset.
"""
return self.action(self.name, qs, value)
lookups = ALL_LOOKUPS
73 changes: 3 additions & 70 deletions rest_framework_filters/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from collections import OrderedDict
import copy
import warnings

from django.db.models.constants import LOOKUP_SEP
from django.utils import six
Expand All @@ -14,38 +13,11 @@
from . import utils


def _base(f):
f._base = True
return f


def _get_fix_filter_field(cls):
method = getattr(cls, 'fix_filter_field')
if not getattr(method, '_base', False):
warnings.warn(
'fix_filter_field is deprecated and no longer necessary. See: '
'https://github.com/philipn/django-rest-framework-filters/issues/62',
DeprecationWarning, stacklevel=2
)
return cls.fix_filter_field


class FilterSetMetaclass(filterset.FilterSetMetaclass):
def __new__(cls, name, bases, attrs):
new_class = super(FilterSetMetaclass, cls).__new__(cls, name, bases, attrs)
fix_filter_field = _get_fix_filter_field(new_class)
opts = copy.deepcopy(new_class._meta)

# order_by is not compatible.
if opts.order_by:
opts.order_by = False
warnings.warn(
'order_by is no longer supported. Use '
'rest_framework.filters.OrderingFilter instead. See: '
'https://github.com/philipn/django-rest-framework-filters/issues/72',
DeprecationWarning, stacklevel=2
)

# If no model is defined, skip all lookups processing
if not opts.model:
return new_class
Expand Down Expand Up @@ -76,12 +48,6 @@ def __new__(cls, name, bases, attrs):

# re-apply declared filters (sans `AllLookupsFilter`s)
new_class.base_filters.update(declared_filters)

# TODO: remove with deprecations
for name, filter_ in six.iteritems(new_class.base_filters.copy()):
if name not in new_class.declared_filters:
new_class.base_filters[name] = fix_filter_field(filter_)

return new_class

@property
Expand All @@ -100,26 +66,6 @@ def related_filters(self):
class FilterSet(six.with_metaclass(FilterSetMetaclass, rest_framework.FilterSet)):
_subset_cache = {}

def __init__(self, *args, **kwargs):
if 'cache' in kwargs:
warnings.warn(
"'cache' argument is deprecated. Override '_subset_cache' instead.",
DeprecationWarning, stacklevel=2
)
self.__class__._subset_cache = kwargs.pop('cache', None)

super(FilterSet, self).__init__(*args, **kwargs)

for name, filter_ in six.iteritems(self.filters.copy()):
if isinstance(filter_, filters.RelatedFilter):
# Add an 'isnull' filter to allow checking if the relation is empty.
filter_name = "%s%sisnull" % (filter_.name, LOOKUP_SEP)
if filter_name not in self.filters:
self.filters[filter_name] = filters.BooleanFilter(name=filter_.name, lookup_expr='isnull')

elif isinstance(filter_, filters.MethodFilter):
filter_.resolve_action()

@classmethod
def filters_for_model(cls, model, opts):
fields = opts.fields
Expand All @@ -131,14 +77,6 @@ def filters_for_model(cls, model, opts):
fields = fields.copy()
for name, lookups in six.iteritems(fields):
if lookups == filters.ALL_LOOKUPS:
warnings.warn(
"ALL_LOOKUPS has been deprecated in favor of '__all__'. See: "
"https://github.com/philipn/django-rest-framework-filters/issues/62",
DeprecationWarning, stacklevel=2
)
lookups = '__all__'

if lookups == '__all__':
field = model._meta.get_field(name)
fields[name] = utils.lookups_for_field(field)

Expand Down Expand Up @@ -291,9 +229,9 @@ class FilterSubsetMetaclass(FilterSetMetaclass):
def __new__(cls, name, bases, attrs):
new_class = super(FilterSubsetMetaclass, cls).__new__(cls, name, bases, attrs)
new_class.base_filters = OrderedDict([
(name, f)
for name, f in six.iteritems(new_class.base_filters)
if name in filter_names
(param, f)
for param, f in six.iteritems(new_class.base_filters)
if param in filter_names
])
return new_class

Expand Down Expand Up @@ -326,8 +264,3 @@ def qs(self):
self.filters = available_filters

return qs

@classmethod
@_base
def fix_filter_field(cls, f):
return f
Loading