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: