From fe55c23b74da7c01284da4714ccf8369f94cdb33 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Sun, 15 Sep 2024 14:08:41 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20du=20rendu=20mois?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix #144 (sans catégorie en doblon) - tri des catégories suivant position --- src/agenda_culturel/calendar.py | 22 ++++++++++++++----- .../templates/agenda_culturel/day-inc.html | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/agenda_culturel/calendar.py b/src/agenda_culturel/calendar.py index 9ea82eb..322a80c 100644 --- a/src/agenda_culturel/calendar.py +++ b/src/agenda_culturel/calendar.py @@ -73,15 +73,16 @@ class DayInCalendar: self._add_event_internal(event) def _add_event_internal(self, event): + from .models import Category + self.events.append(event) if event.category is None: - if "" not in self.events_by_category: - self.events_by_category[""] = [] - self.events_by_category[""].append(event) + cat = Category.default_name else: - if event.category.name not in self.events_by_category: - self.events_by_category[event.category.name] = [] - self.events_by_category[event.category.name].append(event) + cat = event.category.name + if cat not in self.events_by_category: + self.events_by_category[cat] = [] + self.events_by_category[cat].append(event) def filter_events(self): self.events.sort( @@ -90,6 +91,15 @@ class DayInCalendar: else e.start_time ) + def events_by_category_ordered(self): + from .models import Category + cats = Category.objects.order_by('position') + result = [] + for c in cats: + if c.name in self.events_by_category: + result.append((c.name, self.events_by_category[c.name])) + return result + class CalendarList: def __init__(self, firstdate, lastdate, filter=None, exact=False): diff --git a/src/agenda_culturel/templates/agenda_culturel/day-inc.html b/src/agenda_culturel/templates/agenda_culturel/day-inc.html index 620dbde..873ea0b 100644 --- a/src/agenda_culturel/templates/agenda_culturel/day-inc.html +++ b/src/agenda_culturel/templates/agenda_culturel/day-inc.html @@ -25,7 +25,7 @@ {% if day.events %} {% if resume %}