summaryrefslogtreecommitdiff
path: root/patchwork
diff options
context:
space:
mode:
authorStephen Finucane <stephen@that.guru>2020-04-08 22:28:29 +0100
committerStephen Finucane <stephen@that.guru>2020-04-08 23:30:49 +0100
commit438cba6d1cb7517432cab6f0ee6adfb84f53def4 (patch)
tree7d11ebf9fd31a579e72d5792f6ca217a8a502bb0 /patchwork
parent82e352ae5b4c2f9be666fdccea96845c1dc14d5b (diff)
downloadpatchwork-438cba6d1cb7517432cab6f0ee6adfb84f53def4.tar
patchwork-438cba6d1cb7517432cab6f0ee6adfb84f53def4.tar.gz
Remove unnecessary compat wrappers
This will probably need to be reintroduced with future Django versions, but for now it's gone. Signed-off-by: Stephen Finucane <stephen@that.guru>
Diffstat (limited to 'patchwork')
-rw-r--r--patchwork/api/filters.py18
-rw-r--r--patchwork/compat.py44
-rw-r--r--patchwork/settings/base.py2
3 files changed, 16 insertions, 48 deletions
diff --git a/patchwork/api/filters.py b/patchwork/api/filters.py
index f7b6a6f..deb5ace 100644
--- a/patchwork/api/filters.py
+++ b/patchwork/api/filters.py
@@ -6,15 +6,16 @@
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.db.models import Q
+from django_filters import rest_framework
from django_filters.rest_framework import FilterSet
from django_filters import CharFilter
from django_filters import IsoDateTimeFilter
from django_filters import ModelMultipleChoiceFilter
from django.forms import ModelMultipleChoiceField as BaseMultipleChoiceField
from django.forms.widgets import MultipleHiddenInput
+from rest_framework import exceptions
from patchwork.api import utils
-from patchwork.compat import NAME_FIELD
from patchwork.models import Bundle
from patchwork.models import Check
from patchwork.models import CoverLetter
@@ -26,6 +27,17 @@ from patchwork.models import Series
from patchwork.models import State
+# custom backend
+
+class DjangoFilterBackend(rest_framework.DjangoFilterBackend):
+
+ def filter_queryset(self, request, queryset, view):
+ try:
+ return super().filter_queryset(request, queryset, view)
+ except exceptions.ValidationError:
+ return queryset.none()
+
+
# custom fields, filters
class ModelMultipleChoiceField(BaseMultipleChoiceField):
@@ -158,8 +170,8 @@ class BaseFilterSet(FilterSet):
class TimestampMixin(BaseFilterSet):
# TODO(stephenfin): These should filter on a 'updated_at' field instead
- before = IsoDateTimeFilter(lookup_expr='lt', **{NAME_FIELD: 'date'})
- since = IsoDateTimeFilter(lookup_expr='gte', **{NAME_FIELD: 'date'})
+ before = IsoDateTimeFilter(lookup_expr='lt', field_name='date')
+ since = IsoDateTimeFilter(lookup_expr='gte', field_name='date')
class SeriesFilterSet(TimestampMixin, BaseFilterSet):
diff --git a/patchwork/compat.py b/patchwork/compat.py
deleted file mode 100644
index 8d94960..0000000
--- a/patchwork/compat.py
+++ /dev/null
@@ -1,44 +0,0 @@
-# Patchwork - automated patch tracking system
-# Copyright (C) 2016 Intel Corporation
-#
-# SPDX-License-Identifier: GPL-2.0-or-later
-
-"""Compatibility wrappers for various library versions."""
-
-from django.conf import settings
-
-
-# NAME_FIELD
-#
-# The django-filter library renamed 'Filter.name' to 'Filter.field_name' in
-# 1.1.
-#
-# DjangoFilterBackend
-
-# The django-filter library changed the default strictness level in 2.0
-#
-# https://django-filter.readthedocs.io/en/master/guide/migration.html#migrating-to-2-0
-
-if settings.ENABLE_REST_API:
- import django_filters # noqa
- from django_filters import rest_framework # noqa
- from rest_framework import exceptions # noqa
-
- if django_filters.VERSION >= (1, 1):
- NAME_FIELD = 'field_name'
- else:
- NAME_FIELD = 'name'
-
- if django_filters.VERSION >= (2, 0):
- # TODO(stephenfin): Enable strict mode in API v2.0, possibly with a
- # bump in the minimum version of django-filter [1]
- #
- # [1] https://github.com/carltongibson/django-filter/pull/983
- class DjangoFilterBackend(rest_framework.DjangoFilterBackend):
- def filter_queryset(self, request, queryset, view):
- try:
- return super().filter_queryset(request, queryset, view)
- except exceptions.ValidationError:
- return queryset.none()
- else:
- DjangoFilterBackend = rest_framework.DjangoFilterBackend
diff --git a/patchwork/settings/base.py b/patchwork/settings/base.py
index 5160b4f..001878a 100644
--- a/patchwork/settings/base.py
+++ b/patchwork/settings/base.py
@@ -125,7 +125,7 @@ REST_FRAMEWORK = {
'rest_framework.versioning.URLPathVersioning',
'DEFAULT_PAGINATION_CLASS': 'patchwork.api.base.LinkHeaderPagination',
'DEFAULT_FILTER_BACKENDS': (
- 'patchwork.compat.DjangoFilterBackend',
+ 'patchwork.api.filters.DjangoFilterBackend',
'rest_framework.filters.SearchFilter',
'rest_framework.filters.OrderingFilter',
),