]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
Remove unnecessary compat wrappers
authorStephen Finucane <stephen@that.guru>
Wed, 8 Apr 2020 21:28:29 +0000 (22:28 +0100)
committerStephen Finucane <stephen@that.guru>
Wed, 8 Apr 2020 22:30:49 +0000 (23:30 +0100)
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>
patchwork/api/filters.py
patchwork/compat.py [deleted file]
patchwork/settings/base.py

index f7b6a6f66f2227e8a510911b694aeba27f6bc0ca..deb5ace11880893f6f161a96e21fbb96e66ffade 100644 (file)
@@ -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 (file)
index 8d94960..0000000
+++ /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
index 5160b4fabf5a5a574c2bdbef2a6aaa1380bbbfe2..001878acb134444f664d27dcc6bee56686d05e2f 100644 (file)
@@ -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',
     ),