From 9377be0ae854ffbb711bb24fafcf72dfb1979ce5 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Tue, 7 Nov 2023 19:13:40 +0100 Subject: [PATCH] =?UTF-8?q?on=20met=20les=20=C3=A9v=C3=A9nements=20sans=20?= =?UTF-8?q?heure=20=C3=A0=20la=20fin=20de=20la=20journ=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agenda_culturel/views.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 492441c..c8f264b 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -11,7 +11,7 @@ from .celery import create_event_from_submission from .models import Event, Category from django.utils import timezone from enum import StrEnum -from datetime import datetime, timedelta, date +from datetime import datetime, timedelta, date, time import calendar from django.db.models import Q @@ -36,10 +36,12 @@ def daterange(start, end, step=timedelta(1)): class CalendarDay: + midnight = time(23, 59, 59) def __init__(self, d, on_requested_interval = True): self.date = d now = date.today() + self.in_past = d < now self.today = d == now self.events = [] @@ -63,6 +65,9 @@ class CalendarDay: self.events_by_category[event.category.name] = [] self.events_by_category[event.category.name].append(event) + def filter_events(self): + self.events.sort(key=lambda e: CalendarDay.midnight if e.start_time is None else e.start_time) + class CalendarList: @@ -84,6 +89,10 @@ class CalendarList: # fill CalendarDays with events self.fill_calendar_days() + # finally, sort each CalendarDay + for i, c in self.calendar_days.items(): + c.filter_events() + def today_in_calendar(self): return self.firstdate <= self.now and self.lastdate >= self.now