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: if django_filters:
from django_filters.filterset import FilterSetMetaclass as DFFilterSetMetaclass
from django_filters.rest_framework.filterset import FilterSet as DFFilterSet from django_filters.rest_framework.filterset import FilterSet as DFFilterSet
class FilterSetMetaclass(DFFilterSetMetaclass): class FilterSet(DFFilterSet):
def __new__(cls, name, bases, attrs): def __init__(self, *args, **kwargs):
warnings.warn( warnings.warn(
"The built in 'rest_framework.filters.FilterSet' is pending deprecation. " "The built in 'rest_framework.filters.FilterSet' is pending deprecation. "
"You should use 'django_filters.rest_framework.FilterSet' instead.", "You should use 'django_filters.rest_framework.FilterSet' instead.",
PendingDeprecationWarning PendingDeprecationWarning
) )
return super(FilterSetMetaclass, cls).__new__(cls, name, bases, attrs) return super(FilterSet, self).__init__(*args, **kwargs)
_BaseFilterSet = DFFilterSet
else: else:
# Dummy metaclass just so we can give a user-friendly error message. def FilterSet():
class FilterSetMetaclass(type): assert False, 'django-filter must be installed to use the `FilterSet` class'
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
class DjangoFilterBackend(BaseFilterBackend): class DjangoFilterBackend(BaseFilterBackend):