From bb4bd60b1bca211251948cbaf12cda4b11bb6cc7 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Sat, 21 Sep 2024 19:02:56 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20de=20la=20gestion=20des=20=C3=A9v?= =?UTF-8?q?=C3=A9nements=20dans=20un=20jour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - correction de l'ordre (sans heure en premier) - Fix #154 --- src/agenda_culturel/calendar.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/agenda_culturel/calendar.py b/src/agenda_culturel/calendar.py index 0485dcb..4db3056 100644 --- a/src/agenda_culturel/calendar.py +++ b/src/agenda_culturel/calendar.py @@ -19,7 +19,7 @@ def daterange(start, end, step=timedelta(1)): class DayInCalendar: - midnight = time(23, 59, 59) + midnight = time(0, 0, 0) def __init__(self, d, on_requested_interval=True): self.date = d @@ -74,15 +74,29 @@ class DayInCalendar: def _add_event_internal(self, event): from .models import Category + from copy import deepcopy + # copy event + local_event = deepcopy(event) - self.events.append(event) - if event.category is None: + # set values + if local_event.start_day != self.date: + local_event.start_day = self.date + local_event.start_time = None + if local_event.end_day != self.date: + local_event.end_day = None + local_event.end_time = None + + # add event to the day + self.events.append(local_event) + + # add in its category + if local_event.category is None: cat = Category.default_name else: - cat = event.category.name + cat = local_event.category.name if cat not in self.events_by_category: self.events_by_category[cat] = [] - self.events_by_category[cat].append(event) + self.events_by_category[cat].append(local_event) def filter_events(self): self.events.sort(