diff --git a/docs/source/others/changelog.rst b/docs/source/others/changelog.rst index 7f3d3c44..5bd04dec 100644 --- a/docs/source/others/changelog.rst +++ b/docs/source/others/changelog.rst @@ -2,12 +2,13 @@ Changelog ========== -2024.02.7 (2024-02-07) +2024.02.7 (2024-02-15) --------------------------- **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..b9b2944b 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"), @@ -52,6 +53,15 @@ class SourceFilterSet(filters.FilterSet): ) ) + def filter_status(self, qs, name, value): + if value is not None and value != "": + + # WMTS sources should be excluded from status filter + qs = qs.filter(status=int(value)).exclude( + polymorphic_ctype__model__icontains="wmts" + ) + return qs + class Meta: model = Source fields = ( diff --git a/project/geosource/tests/factories.py b/project/geosource/tests/factories.py index 9557b79e..aab7cb74 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,12 @@ class PostGISSourceFactory(factory.django.DjangoModelFactory): class Meta: model = PostGISSource + + +class WMTSSourceFactory(factory.django.DjangoModelFactory): + name = factory.Faker("name") + url = factory.Faker("url") + tile_size = 256 + + class Meta: + model = WMTSSource diff --git a/project/geosource/tests/test_api.py b/project/geosource/tests/test_api.py index fa77074b..9764093e 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,15 @@ 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) + data = response.json()["results"] + self.assertNotIn("WMTSSource", [d["_type"] for d in data]) + def test_property_values(self): source = GeoJSONSource.objects.create( name="foo",