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 %}