From 67f3306156908b7d7723b3a7a76ec9e8dd8c8291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20No=C3=A9?= Date: Thu, 7 Nov 2024 14:38:49 +0100 Subject: [PATCH] Fixed an issue with the maps API --- CHANGELOG.md | 4 ++++ dashboard/tests/views/test_maps.py | 15 +++++++++++++++ dashboard/views/maps.py | 6 +++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4561172..822a517 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# Current (unreleased) + +- Fixed a bg with the maps API (see https://github.com/riparias/gbif-alert/issues/283) + # v1.7.6 (2024-07-26) - Another map performance improvement (missing index) diff --git a/dashboard/tests/views/test_maps.py b/dashboard/tests/views/test_maps.py index 392522c..e0beedf 100644 --- a/dashboard/tests/views/test_maps.py +++ b/dashboard/tests/views/test_maps.py @@ -118,6 +118,21 @@ def setUpTestData(cls): class MinMaxPerHexagonTests(MapsTestDataMixin, TestCase): """Tests covering the min_max_in_hexagon endpoint""" + def test_min_max_status_area_combinations(self): + """Regression test for https://github.com/riparias/gbif-alert/issues/283""" + self.client.login(username="frusciante", password="12345") + + response = self.client.get( + reverse("dashboard:internal-api:maps:mvt-min-max-per-hexagon"), + data={ + "zoom": 8, + "status": "seen", + "areaIds[]": self.public_area_andenne.pk, + }, + ) + + self.assertEqual(response.status_code, 200) + def test_min_max_per_hexagon(self): # At zoom level 8, with the initial data: we should have two polygons, both at 1. So min=1 and max=1 response = self.client.get( diff --git a/dashboard/views/maps.py b/dashboard/views/maps.py index f1134e8..6bc5407 100644 --- a/dashboard/views/maps.py +++ b/dashboard/views/maps.py @@ -251,7 +251,11 @@ def observation_min_max_in_hex_grid_json(request: HttpRequest): LEFT JOIN dashboard_species as species ON obs.species_id = species.id {% if area_ids %} - ,(SELECT mpoly FROM $areas_table_name WHERE $areas_table_name.id IN {{ area_ids | inclause }}) AS areas + LEFT JOIN ( + SELECT mpoly + FROM $areas_table_name + WHERE $areas_table_name.id IN {{ area_ids | inclause }} + ) AS areas ON ST_Within(obs.location, areas.mpoly) {% endif %} {% if status == 'seen' %} INNER JOIN $observationview_table_name