diff --git a/django_filters/conf.py b/django_filters/conf.py index c672c30a7..b0a102767 100644 --- a/django_filters/conf.py +++ b/django_filters/conf.py @@ -8,7 +8,6 @@ from .constants import STRICTNESS from .utils import deprecate - DEFAULTS = { 'DISABLE_HELP_TEXT': False, 'HELP_TEXT_FILTER': True, diff --git a/django_filters/fields.py b/django_filters/fields.py index 160f41928..8be680a04 100644 --- a/django_filters/fields.py +++ b/django_filters/fields.py @@ -1,17 +1,15 @@ -from __future__ import absolute_import -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals -from datetime import datetime, time from collections import namedtuple +from datetime import datetime, time from django import forms from django.utils.dateparse import parse_datetime - from django.utils.encoding import force_str from django.utils.translation import ugettext_lazy as _ from .utils import handle_timezone -from .widgets import RangeWidget, LookupTypeWidget, CSVWidget, BaseCSVWidget +from .widgets import BaseCSVWidget, CSVWidget, LookupTypeWidget, RangeWidget class RangeField(forms.MultiValueField): diff --git a/django_filters/filters.py b/django_filters/filters.py index 975333e64..46bcd2e04 100644 --- a/django_filters/filters.py +++ b/django_filters/filters.py @@ -1,13 +1,12 @@ -from __future__ import absolute_import -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from collections import OrderedDict from datetime import timedelta from django import forms from django.db.models import Q -from django.db.models.sql.constants import QUERY_TERMS from django.db.models.constants import LOOKUP_SEP +from django.db.models.sql.constants import QUERY_TERMS from django.utils import six from django.utils.itercompat import is_iterable from django.utils.timezone import now @@ -16,13 +15,11 @@ from .compat import pretty_name from .conf import settings from .constants import EMPTY_VALUES -from .fields import ( - Lookup, LookupTypeField, BaseCSVField, BaseRangeField, RangeField, - DateRangeField, DateTimeRangeField, TimeRangeField, IsoDateTimeField -) +from .fields import (BaseCSVField, BaseRangeField, DateRangeField, + DateTimeRangeField, IsoDateTimeField, Lookup, + LookupTypeField, RangeField, TimeRangeField) from .utils import label_for_filter - __all__ = [ 'AllValuesFilter', 'AllValuesMultipleFilter', diff --git a/django_filters/filterset.py b/django_filters/filterset.py index 22b40c3ba..9534b7027 100644 --- a/django_filters/filterset.py +++ b/django_filters/filterset.py @@ -1,5 +1,4 @@ -from __future__ import absolute_import -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals import copy from collections import OrderedDict @@ -10,13 +9,15 @@ from django.db.models.fields.related import ForeignObjectRel from django.utils import six -from .conf import settings from .compat import remote_field, remote_queryset -from .constants import ALL_FIELDS, STRICTNESS, EMPTY_VALUES -from .filters import (Filter, CharFilter, BooleanFilter, BaseInFilter, BaseRangeFilter, - ChoiceFilter, DateFilter, DateTimeFilter, TimeFilter, ModelChoiceFilter, - ModelMultipleChoiceFilter, NumberFilter, UUIDFilter, DurationFilter) -from .utils import try_dbfield, get_all_model_fields, get_model_field, resolve_field +from .conf import settings +from .constants import ALL_FIELDS, EMPTY_VALUES, STRICTNESS +from .filters import (BaseInFilter, BaseRangeFilter, BooleanFilter, CharFilter, + ChoiceFilter, DateFilter, DateTimeFilter, DurationFilter, + Filter, ModelChoiceFilter, ModelMultipleChoiceFilter, + NumberFilter, TimeFilter, UUIDFilter) +from .utils import (get_all_model_fields, get_model_field, resolve_field, + try_dbfield) def get_filter_name(field_name, lookup_expr): diff --git a/django_filters/rest_framework/backends.py b/django_filters/rest_framework/backends.py index 7c79bd898..764028fe4 100644 --- a/django_filters/rest_framework/backends.py +++ b/django_filters/rest_framework/backends.py @@ -1,12 +1,13 @@ from __future__ import absolute_import + import warnings from django.template import loader from django.utils import six +from . import filters, filterset from .. import compat -from . import filterset, filters class DjangoFilterBackend(object): diff --git a/django_filters/rest_framework/filterset.py b/django_filters/rest_framework/filterset.py index 3faf28b3e..b4d70dcf4 100644 --- a/django_filters/rest_framework/filterset.py +++ b/django_filters/rest_framework/filterset.py @@ -1,15 +1,15 @@ from __future__ import absolute_import + from copy import deepcopy -from django.db import models from django import forms +from django.db import models from django.utils.translation import ugettext_lazy as _ - from django_filters import filterset -from .filters import BooleanFilter, IsoDateTimeFilter -from .. import compat, utils +from .. import compat, utils +from .filters import BooleanFilter, IsoDateTimeFilter FILTER_FOR_DBFIELD_DEFAULTS = deepcopy(filterset.FILTER_FOR_DBFIELD_DEFAULTS) FILTER_FOR_DBFIELD_DEFAULTS.update({ diff --git a/django_filters/utils.py b/django_filters/utils.py index 4f6f62690..1dda7b0a3 100644 --- a/django_filters/utils.py +++ b/django_filters/utils.py @@ -1,13 +1,13 @@ -import django import warnings +import django from django.conf import settings from django.core.exceptions import FieldError from django.db import models from django.db.models.constants import LOOKUP_SEP from django.db.models.expressions import Expression from django.db.models.fields import FieldDoesNotExist -from django.db.models.fields.related import RelatedField, ForeignObjectRel +from django.db.models.fields.related import ForeignObjectRel, RelatedField from django.forms import ValidationError from django.utils import six, timezone from django.utils.encoding import force_text diff --git a/django_filters/views.py b/django_filters/views.py index daa8418fa..57ffcb162 100644 --- a/django_filters/views.py +++ b/django_filters/views.py @@ -1,11 +1,12 @@ -from __future__ import absolute_import -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals + from django.core.exceptions import ImproperlyConfigured from django.views.generic import View -from django.views.generic.list import MultipleObjectMixin -from django.views.generic.list import MultipleObjectTemplateResponseMixin -from .filterset import filterset_factory +from django.views.generic.list import (MultipleObjectMixin, + MultipleObjectTemplateResponseMixin) + from .constants import ALL_FIELDS +from .filterset import filterset_factory class FilterMixin(object): diff --git a/django_filters/widgets.py b/django_filters/widgets.py index 333af08a7..60adaecce 100644 --- a/django_filters/widgets.py +++ b/django_filters/widgets.py @@ -1,18 +1,15 @@ -from __future__ import absolute_import -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from collections import Iterable from itertools import chain -from django.utils.http import urlencode import django from django import forms from django.db.models.fields import BLANK_CHOICE_DASH - from django.forms.utils import flatatt - from django.utils.datastructures import MultiValueDict from django.utils.encoding import force_text +from django.utils.http import urlencode from django.utils.safestring import mark_safe from django.utils.six import string_types from django.utils.translation import ugettext as _ diff --git a/tests/models.py b/tests/models.py index 857492fe9..848e7f36e 100644 --- a/tests/models.py +++ b/tests/models.py @@ -1,12 +1,10 @@ -from __future__ import absolute_import -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from django import forms from django.db import models from django.utils.encoding import python_2_unicode_compatible from django.utils.translation import ugettext_lazy as _ - REGULAR = 0 MANAGER = 1 ADMIN = 2 diff --git a/tests/rest_framework/test_backends.py b/tests/rest_framework/test_backends.py index 708f7ae30..af4cd677c 100644 --- a/tests/rest_framework/test_backends.py +++ b/tests/rest_framework/test_backends.py @@ -1,21 +1,19 @@ from __future__ import unicode_literals import datetime +import warnings from decimal import Decimal from unittest import skipIf -import warnings from django.db.models import BooleanField from django.test import TestCase from django.test.utils import override_settings - +from django_filters import compat, filters +from django_filters.rest_framework import (DjangoFilterBackend, FilterSet, + backends) from rest_framework import generics, serializers from rest_framework.test import APIRequestFactory -from django_filters import compat, filters -from django_filters.rest_framework import DjangoFilterBackend, FilterSet -from django_filters.rest_framework import backends - from .models import FilterableItem factory = APIRequestFactory() diff --git a/tests/rest_framework/test_filters.py b/tests/rest_framework/test_filters.py index 872094e26..62114aaca 100644 --- a/tests/rest_framework/test_filters.py +++ b/tests/rest_framework/test_filters.py @@ -1,6 +1,5 @@ from django.test import TestCase - from django_filters.rest_framework import filters from django_filters.widgets import BooleanWidget diff --git a/tests/rest_framework/test_filterset.py b/tests/rest_framework/test_filterset.py index 24eb4b029..1152a2e3f 100644 --- a/tests/rest_framework/test_filterset.py +++ b/tests/rest_framework/test_filterset.py @@ -3,12 +3,11 @@ from django.conf import settings from django.test import TestCase from django.test.utils import override_settings - -from django_filters.rest_framework import FilterSet, filters from django_filters.compat import is_crispy +from django_filters.rest_framework import FilterSet, filters from django_filters.widgets import BooleanWidget -from ..models import User, Article +from ..models import Article, User class ArticleFilter(FilterSet): diff --git a/tests/rest_framework/test_integration.py b/tests/rest_framework/test_integration.py index baffc041c..a1a1e0eca 100644 --- a/tests/rest_framework/test_integration.py +++ b/tests/rest_framework/test_integration.py @@ -7,6 +7,13 @@ from django.test import TestCase from django.test.utils import override_settings from django.utils.dateparse import parse_date +from django_filters import STRICTNESS, filters +from django_filters.rest_framework import DjangoFilterBackend, FilterSet +from rest_framework import generics, serializers, status +from rest_framework.test import APIRequestFactory + +from .models import (BaseFilterableItem, BasicModel, DjangoFilterOrderingModel, + FilterableItem) try: from django.urls import reverse @@ -14,13 +21,8 @@ # Django < 1.10 compatibility from django.core.urlresolvers import reverse -from rest_framework import generics, serializers, status -from rest_framework.test import APIRequestFactory -from django_filters import filters, STRICTNESS -from django_filters.rest_framework import DjangoFilterBackend, FilterSet -from .models import BaseFilterableItem, BasicModel, FilterableItem, DjangoFilterOrderingModel factory = APIRequestFactory() diff --git a/tests/settings.py b/tests/settings.py index a68bb19af..6eaa58e3f 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -3,7 +3,6 @@ from django_filters import STRICTNESS from django_filters.conf import DEFAULTS - DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', diff --git a/tests/test_conf.py b/tests/test_conf.py index c7edc1c35..a644a6de9 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -1,9 +1,7 @@ from django.test import TestCase, override_settings - -from django_filters.conf import settings, is_callable -from django_filters import FilterSet, STRICTNESS - +from django_filters import STRICTNESS, FilterSet +from django_filters.conf import is_callable, settings from tests.models import User diff --git a/tests/test_fields.py b/tests/test_fields.py index 5ffc70712..0e96e8262 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1,18 +1,16 @@ -from __future__ import absolute_import -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals -from datetime import datetime, time, timedelta, tzinfo import decimal +from datetime import datetime, time, timedelta, tzinfo from django import forms from django.test import TestCase, override_settings -from django.utils.timezone import make_aware, get_default_timezone - +from django.utils.timezone import get_default_timezone, make_aware +from django_filters.fields import (BaseCSVField, BaseRangeField, + DateRangeField, DateTimeRangeField, + IsoDateTimeField, Lookup, LookupTypeField, + RangeField, TimeRangeField) from django_filters.widgets import BaseCSVWidget, CSVWidget, RangeWidget -from django_filters.fields import ( - Lookup, LookupTypeField, BaseCSVField, BaseRangeField, RangeField, - DateRangeField, DateTimeRangeField, TimeRangeField, IsoDateTimeField -) def to_d(float_value): diff --git a/tests/test_filtering.py b/tests/test_filtering.py index 62b21f768..9a2361cc2 100644 --- a/tests/test_filtering.py +++ b/tests/test_filtering.py @@ -1,49 +1,29 @@ -from __future__ import absolute_import -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals import datetime -import mock import unittest import django +import mock from django import forms from django.test import TestCase, override_settings -from django.utils import six +from django.utils import six, timezone from django.utils.timezone import now -from django.utils import timezone - -from django_filters.filterset import FilterSet -from django_filters.filters import AllValuesFilter -from django_filters.filters import AllValuesMultipleFilter -from django_filters.filters import CharFilter -from django_filters.filters import ChoiceFilter -from django_filters.filters import DateRangeFilter -from django_filters.filters import DateFromToRangeFilter -from django_filters.filters import DateTimeFromToRangeFilter -from django_filters.filters import DurationFilter -from django_filters.filters import MultipleChoiceFilter -from django_filters.filters import ModelChoiceFilter -from django_filters.filters import TypedMultipleChoiceFilter -from django_filters.filters import ModelMultipleChoiceFilter -from django_filters.filters import NumberFilter -from django_filters.filters import OrderingFilter -from django_filters.filters import RangeFilter -from django_filters.filters import TimeRangeFilter from django_filters.exceptions import FieldLookupError +from django_filters.filters import (AllValuesFilter, AllValuesMultipleFilter, + CharFilter, ChoiceFilter, + DateFromToRangeFilter, DateRangeFilter, + DateTimeFromToRangeFilter, DurationFilter, + ModelChoiceFilter, + ModelMultipleChoiceFilter, + MultipleChoiceFilter, NumberFilter, + OrderingFilter, RangeFilter, + TimeRangeFilter, TypedMultipleChoiceFilter) +from django_filters.filterset import FilterSet -from .models import User -from .models import Comment -from .models import Book -from .models import Article -from .models import Company -from .models import Location -from .models import Account -from .models import BankAccount -from .models import Profile -from .models import Node -from .models import DirectedNode -from .models import STATUS_CHOICES -from .models import SpacewalkRecord +from .models import (STATUS_CHOICES, Account, Article, BankAccount, Book, + Comment, Company, DirectedNode, Location, Node, Profile, + SpacewalkRecord, User) class CharFilterTests(TestCase): diff --git a/tests/test_filters.py b/tests/test_filters.py index 603f3ec02..76e879c98 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -1,54 +1,31 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals -from collections import OrderedDict -from datetime import date, time, timedelta, datetime import inspect -import mock +from collections import OrderedDict +from datetime import date, datetime, time, timedelta +import mock from django import forms from django.test import TestCase, override_settings from django.utils import translation from django.utils.translation import ugettext as _ - from django_filters import filters, widgets -from django_filters.fields import ( - Lookup, - RangeField, - DateRangeField, - DateTimeRangeField, - TimeRangeField, - LookupTypeField, - BaseCSVField) -from django_filters.filters import ( - Filter, - CharFilter, - BooleanFilter, - ChoiceFilter, - MultipleChoiceFilter, - TypedMultipleChoiceFilter, - DateFilter, - DateTimeFilter, - TimeFilter, - DurationFilter, - ModelChoiceFilter, - ModelMultipleChoiceFilter, - NumberFilter, - NumericRangeFilter, - RangeFilter, - DateRangeFilter, - DateFromToRangeFilter, - DateTimeFromToRangeFilter, - TimeRangeFilter, - AllValuesFilter, - BaseCSVFilter, - BaseInFilter, - BaseRangeFilter, - UUIDFilter, - OrderingFilter, - LOOKUP_TYPES) - +from django_filters.fields import (BaseCSVField, DateRangeField, + DateTimeRangeField, Lookup, LookupTypeField, + RangeField, TimeRangeField) +from django_filters.filters import (LOOKUP_TYPES, AllValuesFilter, + BaseCSVFilter, BaseInFilter, + BaseRangeFilter, BooleanFilter, CharFilter, + ChoiceFilter, DateFilter, + DateFromToRangeFilter, DateRangeFilter, + DateTimeFilter, DateTimeFromToRangeFilter, + DurationFilter, Filter, ModelChoiceFilter, + ModelMultipleChoiceFilter, + MultipleChoiceFilter, NumberFilter, + NumericRangeFilter, OrderingFilter, + RangeFilter, TimeFilter, TimeRangeFilter, + TypedMultipleChoiceFilter, UUIDFilter) from tests.models import Book, User diff --git a/tests/test_filterset.py b/tests/test_filterset.py index d2966388e..cd7acf276 100644 --- a/tests/test_filterset.py +++ b/tests/test_filterset.py @@ -1,47 +1,25 @@ from __future__ import absolute_import, unicode_literals -import mock import unittest import django +import mock from django.core.exceptions import ValidationError from django.db import models from django.test import TestCase, override_settings - from django_filters.constants import STRICTNESS -from django_filters.filterset import FilterSet -from django_filters.filterset import FILTER_FOR_DBFIELD_DEFAULTS -from django_filters.filters import Filter -from django_filters.filters import BooleanFilter -from django_filters.filters import CharFilter -from django_filters.filters import NumberFilter -from django_filters.filters import ChoiceFilter -from django_filters.filters import ModelChoiceFilter -from django_filters.filters import ModelMultipleChoiceFilter -from django_filters.filters import UUIDFilter -from django_filters.filters import BaseInFilter -from django_filters.filters import BaseRangeFilter -from django_filters.filters import DateRangeFilter -from django_filters.filters import FilterMethod - +from django_filters.filters import (BaseInFilter, BaseRangeFilter, + BooleanFilter, CharFilter, ChoiceFilter, + DateRangeFilter, Filter, FilterMethod, + ModelChoiceFilter, + ModelMultipleChoiceFilter, NumberFilter, + UUIDFilter) +from django_filters.filterset import FILTER_FOR_DBFIELD_DEFAULTS, FilterSet from django_filters.widgets import BooleanWidget -from .models import User -from .models import AdminUser -from .models import Article -from .models import Book -from .models import Profile -from .models import Comment -from .models import Restaurant -from .models import NetworkSetting -from .models import SubnetMaskField -from .models import Account -from .models import BankAccount -from .models import Node -from .models import DirectedNode -from .models import Worker -from .models import Business -from .models import UUIDTestModel +from .models import (Account, AdminUser, Article, BankAccount, Book, Business, + Comment, DirectedNode, NetworkSetting, Node, Profile, + Restaurant, SubnetMaskField, User, UUIDTestModel, Worker) def checkItemsEqual(L1, L2): diff --git a/tests/test_forms.py b/tests/test_forms.py index f9ff308a7..5be424a6c 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -1,16 +1,11 @@ -from __future__ import absolute_import -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from django import forms from django.test import TestCase, override_settings - +from django_filters.filters import CharFilter, ChoiceFilter from django_filters.filterset import FilterSet -from django_filters.filters import CharFilter -from django_filters.filters import ChoiceFilter -from .models import User, ManagerGroup -from .models import Book -from .models import STATUS_CHOICES, REGULAR, MANAGER +from .models import MANAGER, REGULAR, STATUS_CHOICES, Book, ManagerGroup, User class FilterSetFormTests(TestCase): diff --git a/tests/test_utils.py b/tests/test_utils.py index a164b1f45..ac9bc7726 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,7 +1,7 @@ import datetime import unittest -import django +import django from django.db import models from django.db.models.constants import LOOKUP_SEP from django.db.models.fields.related import ForeignObjectRel @@ -9,24 +9,15 @@ from django.test import TestCase, override_settings from django.utils.functional import Promise from django.utils.timezone import get_default_timezone - -from django_filters import FilterSet, STRICTNESS +from django_filters import STRICTNESS, FilterSet from django_filters.exceptions import FieldLookupError -from django_filters.utils import ( - get_field_parts, get_model_field, resolve_field, handle_timezone, - verbose_field_name, verbose_lookup_expr, label_for_filter, raw_validation, -) - -from .models import ( - User, - Article, - Book, - HiredWorker, - Business, - NetworkSetting, - Company, - Account, -) +from django_filters.utils import (get_field_parts, get_model_field, + handle_timezone, label_for_filter, + raw_validation, resolve_field, + verbose_field_name, verbose_lookup_expr) + +from .models import (Account, Article, Book, Business, Company, HiredWorker, + NetworkSetting, User) class GetFieldPartsTests(TestCase): diff --git a/tests/test_views.py b/tests/test_views.py index b5d29ee2a..49b7fa30e 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,12 +1,10 @@ -from __future__ import absolute_import -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from django.core.exceptions import ImproperlyConfigured from django.test import TestCase, override_settings from django.test.client import RequestFactory - -from django_filters.views import FilterView from django_filters.filterset import FilterSet, filterset_factory +from django_filters.views import FilterView from .models import Book diff --git a/tests/test_widgets.py b/tests/test_widgets.py index 7dd9d5bbc..98a2ca634 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -1,15 +1,10 @@ -from __future__ import absolute_import -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals +from django.forms import Select, TextInput from django.test import TestCase -from django.forms import TextInput, Select - -from django_filters.widgets import BooleanWidget, QueryArrayWidget -from django_filters.widgets import BaseCSVWidget -from django_filters.widgets import CSVWidget -from django_filters.widgets import RangeWidget -from django_filters.widgets import LinkWidget -from django_filters.widgets import LookupTypeWidget +from django_filters.widgets import (BaseCSVWidget, BooleanWidget, CSVWidget, + LinkWidget, LookupTypeWidget, + QueryArrayWidget, RangeWidget) class LookupTypeWidgetTests(TestCase): diff --git a/tests/urls.py b/tests/urls.py index 18c4f7929..ff7ebb61c 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -1,11 +1,11 @@ -from __future__ import absolute_import -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from django.conf.urls import url - from django_filters.views import FilterView, object_filter + from .models import Book + def _foo(): return 'bar'