Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude wmts source from status filters #556

Merged
merged 7 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading