Skip to content

Commit

Permalink
💫 [IMP] Sort API V2 by begin date by default on touristic events (fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien Potiron committed Sep 28, 2023
1 parent 2f12183 commit 083a141
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 5 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ CHANGELOG
- Fix missing update rights for Infrastructure Condition and Infrastructure Type with no structure in Admin Site (#3747)
- Allow to load a signage with the year set to None, raise error if set to NaN (#3611)

**Improvements**

- Sort API V2 by begin date by default on touristic events (#3597)

**New features**

- Sensitivity: Add ``openair`` export format for aerial sensitive areas (#2372)
Expand Down Expand Up @@ -83,7 +87,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)
Expand Down
2 changes: 1 addition & 1 deletion geotrek/api/tests/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3255,7 +3255,7 @@ def test_touristic_event_list_2(self):
# Event with end date returns right end date
self.assertEqual(response.json().get("results")[1]['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'})
Expand Down
8 changes: 2 additions & 6 deletions geotrek/api/v2/views/tourism.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 083a141

Please sign in to comment.