Fix FilterSet warnings. (#4660)

This commit is contained in:
Tom Christie 2016-11-07 12:55:18 +00:00 committed by GitHub
parent 06df61e38c
commit 8d72535be9

View File

@ -38,31 +38,19 @@ class BaseFilterBackend(object):
if django_filters:
from django_filters.filterset import FilterSetMetaclass as DFFilterSetMetaclass
from django_filters.rest_framework.filterset import FilterSet as DFFilterSet
class FilterSetMetaclass(DFFilterSetMetaclass):
def __new__(cls, name, bases, attrs):
class FilterSet(DFFilterSet):
def __init__(self, *args, **kwargs):
warnings.warn(
"The built in 'rest_framework.filters.FilterSet' is pending deprecation. "
"You should use 'django_filters.rest_framework.FilterSet' instead.",
PendingDeprecationWarning
)
return super(FilterSetMetaclass, cls).__new__(cls, name, bases, attrs)
_BaseFilterSet = DFFilterSet
return super(FilterSet, self).__init__(*args, **kwargs)
else:
# Dummy metaclass just so we can give a user-friendly error message.
class FilterSetMetaclass(type):
def __init__(self, name, bases, attrs):
# Assert only on subclasses, so we can define FilterSet below.
if bases != (object,):
assert False, 'django-filter must be installed to use the `FilterSet` class'
super(FilterSetMetaclass, self).__init__(name, bases, attrs)
_BaseFilterSet = object
class FilterSet(six.with_metaclass(FilterSetMetaclass, _BaseFilterSet)):
pass
def FilterSet():
assert False, 'django-filter must be installed to use the `FilterSet` class'
class DjangoFilterBackend(BaseFilterBackend):