api: sort events by date in datetimes endpoint (#75331) #49

Merged
lguerin merged 1 commits from wip/75331-fix-datetimes-ordering into main 2023-03-10 15:31:40 +01:00
2 changed files with 21 additions and 0 deletions

View File

@ -855,6 +855,7 @@ class Datetimes(APIView):
bypass_delays=payload.get('bypass_delays'),
)
entries = Event.annotate_queryset_for_user(entries, user_external_id)
entries = entries.order_by('start_datetime', 'duration', 'label')
if payload['hide_disabled']:
entries = [

View File

@ -82,6 +82,26 @@ def test_datetimes_api_wrong_kind(app):
app.get('/api/agenda/%s/datetimes/' % agenda.slug, status=404)
@pytest.mark.freeze_time('2023-03-10')
def test_datetimes_sort(app):
agenda = Agenda.objects.create(label='Foo bar', kind='events', minimal_booking_delay=0)
Event.objects.create(
slug='event-slug',
start_datetime=localtime(now() + datetime.timedelta(days=5)).replace(hour=17, minute=0),
places=5,
agenda=agenda,
)
Event.objects.create(
slug='event-slug-2',
start_datetime=localtime(now() + datetime.timedelta(days=4)).replace(hour=17, minute=0),
places=5,
agenda=agenda,
)
resp = app.get('/api/agenda/%s/datetimes/' % agenda.slug)
assert resp.json['data'][0]['datetime'] == '2023-03-14 17:00:00'
assert resp.json['data'][1]['datetime'] == '2023-03-15 17:00:00'
def test_datetime_api_fr(app):
agenda = Agenda.objects.create(label='Foo bar', kind='events', minimal_booking_delay=0)
Event.objects.create(