Skip to content

Commit

Permalink
Merge pull request #556 from Terralego/exclude_wmts_status_filter_nee…
Browse files Browse the repository at this point in the history
…d_sync

Exclude wmts source from status filters
  • Loading branch information
submarcos authored Feb 15, 2024
2 parents ee646ec + 52a1cd5 commit 7a47201
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/source/others/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions project/geosource/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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 = (
Expand Down
11 changes: 10 additions & 1 deletion project/geosource/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import factory

from project.geosource.models import PostGISSource
from project.geosource.models import PostGISSource, WMTSSource


class PostGISSourceFactory(factory.django.DjangoModelFactory):
Expand All @@ -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
10 changes: 10 additions & 0 deletions project/geosource/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 7a47201

Please sign in to comment.