From 69ae647b39915c63de4ab21c98d20fd5910d9e1f Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Tue, 7 Nov 2023 18:24:22 +0100 Subject: [PATCH] =?UTF-8?q?Prise=20en=20charge=20des=20=C3=A9v=C3=A9nement?= =?UTF-8?q?s=20sans=20classe=20ni=20tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agenda_culturel/models.py | 7 ++++- src/agenda_culturel/templatetags/cat_extra.py | 31 ++++++++++++------- src/agenda_culturel/views.py | 11 +++++-- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index 27dd471..104a126 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -11,6 +11,10 @@ from datetime import datetime class Category(models.Model): + default_name = "Sans catégorie" + default_css_class = "cat-nocat" + default_color = "#aaaaaa" + COLOR_PALETTE = [ ("#ea5545", "color 1"), ("#f46a9b", "color 2"), @@ -103,7 +107,8 @@ class Event(models.Model): tags = list(Event.objects.values_list('tags', flat = True)) uniq_tags = set() for t in tags: - uniq_tags = uniq_tags | set(t) + if t is not None: + uniq_tags = uniq_tags | set(t) return list(uniq_tags) diff --git a/src/agenda_culturel/templatetags/cat_extra.py b/src/agenda_culturel/templatetags/cat_extra.py index 08ce5ad..08b618b 100644 --- a/src/agenda_culturel/templatetags/cat_extra.py +++ b/src/agenda_culturel/templatetags/cat_extra.py @@ -60,24 +60,25 @@ def background_color_adjust_color(color, alpha = 1): def css_categories(): result = '' @@ -86,12 +87,18 @@ def css_categories(): @register.filter def small_cat(category, url=None, contrast=True): + name = Category.default_name if category is None else category.name + css_class = Category.default_css_class if category is None else category.css_class() + class_contrast = " contrast" if contrast else "" if url is None: - return mark_safe(' ' + category.name + "") + return mark_safe(' ' + name + "") else: - return mark_safe(' ' + category.name + "") + return mark_safe(' ' + name + "") @register.filter def circle_cat(category): - return mark_safe('') \ No newline at end of file + if category is None: + return mark_safe('') + else: + return mark_safe('') \ No newline at end of file diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 85865d0..97e4f2c 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -52,9 +52,14 @@ class CalendarDay: def add_event(self, event): self.events.append(event) - if not event.category.name in self.events_by_category: - self.events_by_category[event.category.name] = [] - self.events_by_category[event.category.name].append(event) + if event.category is None: + if not "" in self.events_by_category: + self.events_by_category[""] = [] + self.events_by_category[""].append(event) + else: + if not event.category.name in self.events_by_category: + self.events_by_category[event.category.name] = [] + self.events_by_category[event.category.name].append(event) class CalendarList: