]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
Add support for django-filter 1.1
authorStephen Finucane <stephen@that.guru>
Sun, 24 Jun 2018 19:55:49 +0000 (20:55 +0100)
committerDaniel Axtens <dja@axtens.net>
Fri, 3 May 2019 06:23:25 +0000 (16:23 +1000)
There's one warning to handle here.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Signed-off-by: Daniel Axtens <dja@axtens.net>
(backported from commit 4ad2558f884bf33201e179a171ad3821a62126a1
 to not include changes to requirements-*.txt, just release note,
 code and tox.ini changes.)
Signed-off-by: Daniel Axtens <dja@axtens.net>
README.rst
patchwork/api/filters.py
patchwork/compat.py
releasenotes/notes/django-filter-1-1-6a6b0ab8cbe0faca.yaml [new file with mode: 0644]
tox.ini

index ddc4b98125d1bdff64d753b97614f0bbff1099d6..94ac32c3b8b7d32572b2d3d29646e0dbe02ee9f0 100644 (file)
@@ -47,7 +47,7 @@ Requirements
 
 - Django REST Framework (3.4 - 3.8)
 
-- Django Filters (1.0)
+- Django Filters (1.0 - 1.1)
 
 Development Installation
 ------------------------
index 73353d900a94e3e25c274b60c7191442a75f33bc..ddf527fd837b097743c4ea754f2a61ccca99378b 100644 (file)
@@ -26,6 +26,7 @@ from django_filters import ModelMultipleChoiceFilter
 from django.forms import ModelMultipleChoiceField as BaseMultipleChoiceField
 from django.forms.widgets import MultipleHiddenInput
 
+from patchwork.compat import NAME_FIELD
 from patchwork.models import Bundle
 from patchwork.models import Check
 from patchwork.models import CoverLetter
@@ -151,8 +152,8 @@ class UserFilter(ModelMultipleChoiceFilter):
 class TimestampMixin(FilterSet):
 
     # TODO(stephenfin): These should filter on a 'updated_at' field instead
-    before = IsoDateTimeFilter(name='date', lookup_expr='lt')
-    since = IsoDateTimeFilter(name='date', lookup_expr='gte')
+    before = IsoDateTimeFilter(lookup_expr='lt', **{NAME_FIELD: 'date'})
+    since = IsoDateTimeFilter(lookup_expr='gte', **{NAME_FIELD: 'date'})
 
 
 class SeriesFilterSet(TimestampMixin, FilterSet):
index 38caa4e861cf0e43f6f3677771bc4ed639a94973..3bbff447dbcbe82db9fdf0cc479c96c87f45f70b 100644 (file)
@@ -41,6 +41,22 @@ if settings.ENABLE_REST_API:
         from rest_framework.filters import DjangoFilterBackend  # noqa
 
 
+# NAME_FIELD
+#
+# The django-filter library renamed 'Filter.name' to 'Filter.field_name' in
+# 1.1.
+#
+# https://django-filter.readthedocs.io/en/master/guide/migration.html#migrating-to-2-0
+
+if settings.ENABLE_REST_API:
+    import django_filters  # noqa
+
+    if django_filters.VERSION >= (1, 1):
+        NAME_FIELD = 'field_name'
+    else:
+        NAME_FIELD = 'name'
+
+
 # reverse, reverse_lazy
 #
 # The reverse and reverse_lazy functions have been moved to django.urls in
diff --git a/releasenotes/notes/django-filter-1-1-6a6b0ab8cbe0faca.yaml b/releasenotes/notes/django-filter-1-1-6a6b0ab8cbe0faca.yaml
new file mode 100644 (file)
index 0000000..3beb9c0
--- /dev/null
@@ -0,0 +1,6 @@
+---
+upgrade:
+  - |
+    `django-filter 1.1
+    <https://github.com/carltongibson/django-filter/releases/tag/1.1.0>`_ is
+    now supported.
diff --git a/tox.ini b/tox.ini
index 5c741d374a643fcee2a4d397618e27ee0b3cbbe7..c242c97f4d8b9c1a3b24a8a1e033e5611ff62191 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -13,7 +13,8 @@ deps =
     django{18,19}: djangorestframework>=3.4,<3.7
     django110: djangorestframework>=3.4,<3.9
     django111: djangorestframework>=3.6,<3.9
-    django{18,19,110,111}: django-filter>=1.0,<1.1
+    django18: django-filter>=1.0,<1.1
+    django{19,110,111}: django-filter>=1.0,<1.2
 setenv =
     DJANGO_SETTINGS_MODULE = patchwork.settings.dev
     PYTHONDONTWRITEBYTECODE = 1