diff --git a/docs/changelog.rst b/docs/changelog.rst index 46b3e02479..a7f94bc701 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -17,6 +17,7 @@ CHANGELOG **Improvements** - Add organizer_id on TouristicEvent endpoint (#3587) +- Sort API V2 by begin date by default on touristic events (#3597) **Maintenance** @@ -90,7 +91,7 @@ CHANGELOG - Filter by multiple structures on Blades list (#3646) - Add a multiselect to filter the Blades by more than one manager -- Filter by begin date by default on touristic events in APIv2 (#3597) +- Filter by end date by default on touristic events in APIv2 (#3597) - Add model LinePictogram for each line (#3327) - Create Organizer model for touristic events, configurable in admin site (#3625) - Improve CSS of the altitude profile of altimetry (#3657) diff --git a/geotrek/api/tests/test_v2.py b/geotrek/api/tests/test_v2.py index 673a7e179c..08643b682c 100644 --- a/geotrek/api/tests/test_v2.py +++ b/geotrek/api/tests/test_v2.py @@ -3247,15 +3247,15 @@ def test_touristic_event_list_2(self): # Only two because past events are filter by default self.assertEqual(response.json().get("count"), 2) # Event with no end date is returned with begin date as end date - self.assertEqual(response.json().get("results")[0]['end_date'], "2022-02-20") + self.assertEqual(response.json().get("results")[1]['end_date'], "2022-02-20") # start_time replaces meeting_time - self.assertEqual(response.json().get("results")[0]['meeting_time'], "12:34:00") + self.assertEqual(response.json().get("results")[1]['meeting_time'], "12:34:00") # capacity replaces participant_number - self.assertEqual(response.json().get("results")[0]['participant_number'], '12') + self.assertEqual(response.json().get("results")[1]['participant_number'], '12') # Event with end date returns right end date - self.assertEqual(response.json().get("results")[1]['end_date'], "2202-02-22") + self.assertEqual(response.json().get("results")[0]['end_date'], "2202-02-22") # Sorted by end date - self.assertLessEqual(response.json().get("results")[0]['end_date'], response.json().get("results")[1]['end_date']) + self.assertLessEqual(response.json().get("results")[0]['begin_date'], response.json().get("results")[1]['begin_date']) def test_touristic_event_dates_filters_1(self): response = self.get_touristicevent_list({'dates_before': '2200-01-01', 'dates_after': '1970-01-01'}) diff --git a/geotrek/api/v2/views/tourism.py b/geotrek/api/v2/views/tourism.py index cbab033097..b70f93db22 100644 --- a/geotrek/api/v2/views/tourism.py +++ b/geotrek/api/v2/views/tourism.py @@ -1,6 +1,6 @@ from django.conf import settings from django.contrib.gis.db.models.functions import Transform -from django.db.models import F, Case, When +from django.db.models import F from django.db.models.query import Prefetch from django.shortcuts import get_object_or_404 from django.utils.translation import activate @@ -100,11 +100,7 @@ def get_queryset(self): queryset=Attachment.objects.select_related('license', 'filetype', 'filetype__structure')) ) \ .annotate(geom_transformed=Transform(F('geom'), settings.API_SRID)) \ - .annotate(ordering_date=Case( - When(end_date__isnull=True, then=F('begin_date')), - default=F('end_date'), - )) \ - .order_by('ordering_date') # Required for reliable pagination + .order_by('begin_date') # Required for reliable pagination class TouristicEventPlaceViewSet(api_viewsets.GeotrekGeometricViewset):