From 02298cc79ca1c950e4a10c6c1cd3a55446f9cee6 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Wed, 7 Feb 2024 16:27:55 +0100 Subject: [PATCH 1/7] exclude WMTS source from status filter --- docs/source/others/changelog.rst | 1 + project/geosource/filters.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/docs/source/others/changelog.rst b/docs/source/others/changelog.rst index 7f3d3c44..7227e73b 100644 --- a/docs/source/others/changelog.rst +++ b/docs/source/others/changelog.rst @@ -8,6 +8,7 @@ Changelog **Bugfix:** - Fix source status sort in admin +- WMTS sources are exclude from filtering by status in admin 2024.02.6 (2024-02-06) diff --git a/project/geosource/filters.py b/project/geosource/filters.py index bc03afbb..8e41e4c0 100644 --- a/project/geosource/filters.py +++ b/project/geosource/filters.py @@ -52,6 +52,12 @@ class SourceFilterSet(filters.FilterSet): ) ) + def filter_status(self, queryset, name, value): + if value: + # WMTS sources should be excluded from status filter + return queryset.filter(status=value).exclude(polymorphic_ctype__model__icontains="wmts") + return + class Meta: model = Source fields = ( From 641f88d31fde1b5ed0355457d65495a747a85346 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Wed, 7 Feb 2024 16:34:48 +0100 Subject: [PATCH 2/7] add test --- project/geosource/filters.py | 4 +++- project/geosource/tests/factories.py | 10 +++++++++- project/geosource/tests/test_api.py | 9 +++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/project/geosource/filters.py b/project/geosource/filters.py index 8e41e4c0..52b32df0 100644 --- a/project/geosource/filters.py +++ b/project/geosource/filters.py @@ -55,7 +55,9 @@ class SourceFilterSet(filters.FilterSet): def filter_status(self, queryset, name, value): if value: # WMTS sources should be excluded from status filter - return queryset.filter(status=value).exclude(polymorphic_ctype__model__icontains="wmts") + return queryset.filter(status=value).exclude( + polymorphic_ctype__model__icontains="wmts" + ) return class Meta: diff --git a/project/geosource/tests/factories.py b/project/geosource/tests/factories.py index 9557b79e..786bf774 100644 --- a/project/geosource/tests/factories.py +++ b/project/geosource/tests/factories.py @@ -1,6 +1,6 @@ import factory -from project.geosource.models import PostGISSource +from project.geosource.models import PostGISSource, WMTSSource class PostGISSourceFactory(factory.django.DjangoModelFactory): @@ -13,3 +13,11 @@ class PostGISSourceFactory(factory.django.DjangoModelFactory): class Meta: model = PostGISSource + + +class WMTSSourceFactory(factory.django.DjangoModelFactory): + name = factory.Faker("name") + url = factory.Faker("url") + + class Meta: + model = WMTSSource diff --git a/project/geosource/tests/test_api.py b/project/geosource/tests/test_api.py index fa77074b..f7400257 100644 --- a/project/geosource/tests/test_api.py +++ b/project/geosource/tests/test_api.py @@ -18,6 +18,7 @@ Source, SourceReporting, ) +from project.geosource.tests.factories import WMTSSourceFactory from project.geosource.tests.helpers import get_file UserModel = get_user_model() @@ -413,6 +414,14 @@ def test_ordering_filtering_search(self): self.assertEqual(len(data), 1) self.assertEqual(data[0]["name"], obj2.name) + def test_wmts_is_excluded_from_status_filter(self): + WMTSSourceFactory(status=Source.Status.NEED_SYNC) + response = self.client.get( + reverse("geosource:geosource-list"), {"status": Source.Status.NEED_SYNC} + ) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(len(response.json()["results"]), 0) + def test_property_values(self): source = GeoJSONSource.objects.create( name="foo", From eb8c52c1932dfb274a14c5f5f6803432086e7988 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Wed, 7 Feb 2024 17:16:19 +0100 Subject: [PATCH 3/7] fix test --- project/geosource/tests/factories.py | 1 + 1 file changed, 1 insertion(+) diff --git a/project/geosource/tests/factories.py b/project/geosource/tests/factories.py index 786bf774..aab7cb74 100644 --- a/project/geosource/tests/factories.py +++ b/project/geosource/tests/factories.py @@ -18,6 +18,7 @@ class Meta: class WMTSSourceFactory(factory.django.DjangoModelFactory): name = factory.Faker("name") url = factory.Faker("url") + tile_size = 256 class Meta: model = WMTSSource From c612ba0acec4cbe8655ea8e0b76e84df77609b97 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Thu, 15 Feb 2024 14:44:20 +0100 Subject: [PATCH 4/7] fix wmts filter on status --- project/geosource/filters.py | 8 +++++--- project/geosource/tests/test_api.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/project/geosource/filters.py b/project/geosource/filters.py index 52b32df0..661a0d9a 100644 --- a/project/geosource/filters.py +++ b/project/geosource/filters.py @@ -39,6 +39,7 @@ def filter(self, qs, value): class SourceFilterSet(filters.FilterSet): q = filters.CharFilter(field_name="name", lookup_expr="icontains") + status = filters.ChoiceFilter(choices=Source.Status.choices, method="filter_status") ordering = SourceOrderingFilter( fields=( ("name", "name"), @@ -53,12 +54,13 @@ class SourceFilterSet(filters.FilterSet): ) def filter_status(self, queryset, name, value): - if value: + if value is not None and value != '': + # WMTS sources should be excluded from status filter - return queryset.filter(status=value).exclude( + return queryset.filter(status=int(value)).exclude( polymorphic_ctype__model__icontains="wmts" ) - return + return queryset class Meta: model = Source diff --git a/project/geosource/tests/test_api.py b/project/geosource/tests/test_api.py index f7400257..9017f4c4 100644 --- a/project/geosource/tests/test_api.py +++ b/project/geosource/tests/test_api.py @@ -420,7 +420,8 @@ def test_wmts_is_excluded_from_status_filter(self): reverse("geosource:geosource-list"), {"status": Source.Status.NEED_SYNC} ) self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(len(response.json()["results"]), 0) + data = response.json()["results"] + self.assertNotIn("WMTSSource", [d['_type'] for d in data]) def test_property_values(self): source = GeoJSONSource.objects.create( From 2f1893bb8198b014881f4460c278412f034755f1 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Thu, 15 Feb 2024 14:46:32 +0100 Subject: [PATCH 5/7] lint --- project/geosource/filters.py | 2 +- project/geosource/tests/test_api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project/geosource/filters.py b/project/geosource/filters.py index 661a0d9a..7b512674 100644 --- a/project/geosource/filters.py +++ b/project/geosource/filters.py @@ -54,7 +54,7 @@ class SourceFilterSet(filters.FilterSet): ) def filter_status(self, queryset, name, value): - if value is not None and value != '': + if value is not None and value != "": # WMTS sources should be excluded from status filter return queryset.filter(status=int(value)).exclude( diff --git a/project/geosource/tests/test_api.py b/project/geosource/tests/test_api.py index 9017f4c4..9764093e 100644 --- a/project/geosource/tests/test_api.py +++ b/project/geosource/tests/test_api.py @@ -421,7 +421,7 @@ def test_wmts_is_excluded_from_status_filter(self): ) self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json()["results"] - self.assertNotIn("WMTSSource", [d['_type'] for d in data]) + self.assertNotIn("WMTSSource", [d["_type"] for d in data]) def test_property_values(self): source = GeoJSONSource.objects.create( From 5c4ab8bc35b166ed42c95db139fb10b5a44a8c19 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Thu, 15 Feb 2024 14:47:57 +0100 Subject: [PATCH 6/7] changelog --- docs/source/others/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/others/changelog.rst b/docs/source/others/changelog.rst index 7227e73b..5bd04dec 100644 --- a/docs/source/others/changelog.rst +++ b/docs/source/others/changelog.rst @@ -2,7 +2,7 @@ Changelog ========== -2024.02.7 (2024-02-07) +2024.02.7 (2024-02-15) --------------------------- **Bugfix:** From 52a1cd5e9ff71928a51d55c48e2e623de6bf2817 Mon Sep 17 00:00:00 2001 From: J-E Castagnede Date: Thu, 15 Feb 2024 14:53:14 +0100 Subject: [PATCH 7/7] changelog --- project/geosource/filters.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/project/geosource/filters.py b/project/geosource/filters.py index 7b512674..b9b2944b 100644 --- a/project/geosource/filters.py +++ b/project/geosource/filters.py @@ -53,14 +53,14 @@ class SourceFilterSet(filters.FilterSet): ) ) - def filter_status(self, queryset, name, value): + def filter_status(self, qs, name, value): if value is not None and value != "": # WMTS sources should be excluded from status filter - return queryset.filter(status=int(value)).exclude( + qs = qs.filter(status=int(value)).exclude( polymorphic_ctype__model__icontains="wmts" ) - return queryset + return qs class Meta: model = Source