Prise en charge des événements sans classe ni tag
This commit is contained in:
parent
8f02abe9db
commit
69ae647b39
@ -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,6 +107,7 @@ class Event(models.Model):
|
||||
tags = list(Event.objects.values_list('tags', flat = True))
|
||||
uniq_tags = set()
|
||||
for t in tags:
|
||||
if t is not None:
|
||||
uniq_tags = uniq_tags | set(t)
|
||||
return list(uniq_tags)
|
||||
|
||||
|
@ -60,24 +60,25 @@ def background_color_adjust_color(color, alpha = 1):
|
||||
def css_categories():
|
||||
result = '<style type="text/css">'
|
||||
|
||||
cats = Category.objects.all()
|
||||
cats = [{"color": c.color, "css_class": c.css_class()} for c in Category.objects.all()]
|
||||
cats.append({"color": Category.default_color, "css_class": Category.default_css_class})
|
||||
|
||||
for c in cats:
|
||||
|
||||
result += "." + c.css_class() + " {"
|
||||
result += background_color_adjust_color(adjust_lightness_saturation(c.color, .2, 0.8), 0.8)
|
||||
result += "." + c["css_class"] + " {"
|
||||
result += background_color_adjust_color(adjust_lightness_saturation(c["color"], .2, 0.8), 0.8)
|
||||
result += "}"
|
||||
|
||||
result += "*:hover ." + c.css_class() + " {"
|
||||
result += background_color_adjust_color(adjust_lightness_saturation(c.color, 0.02, 1.0))
|
||||
result += "*:hover ." + c["css_class"] + " {"
|
||||
result += background_color_adjust_color(adjust_lightness_saturation(c["color"], 0.02, 1.0))
|
||||
result += "}"
|
||||
|
||||
result += ".selected ." + c.css_class() + " {"
|
||||
result += background_color_adjust_color(c.color)
|
||||
result += ".selected ." + c["css_class"] + " {"
|
||||
result += background_color_adjust_color(c["color"])
|
||||
result += "}"
|
||||
|
||||
result += "a.selected:hover ." + c.css_class() + " {"
|
||||
result += background_color_adjust_color(adjust_lightness_saturation(c.color, 0.2, 1.2))
|
||||
result += "a.selected:hover ." + c["css_class"] + " {"
|
||||
result += background_color_adjust_color(adjust_lightness_saturation(c["color"], 0.2, 1.2))
|
||||
result += "}"
|
||||
|
||||
result += '</style>'
|
||||
@ -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('<span class="small-cat' + class_contrast +' selected" role="button"><span class="cat ' + category.css_class() + '"></span> ' + category.name + "</span>")
|
||||
return mark_safe('<span class="small-cat' + class_contrast +' selected" role="button"><span class="cat ' + css_class + '"></span> ' + name + "</span>")
|
||||
else:
|
||||
return mark_safe('<a class="small-cat' + class_contrast +' selected" role="button" href="' + url + '"><span class="cat ' + category.css_class() + '"></span> ' + category.name + "</a>")
|
||||
return mark_safe('<a class="small-cat' + class_contrast +' selected" role="button" href="' + url + '"><span class="cat ' + css_class + '"></span> ' + name + "</a>")
|
||||
|
||||
@register.filter
|
||||
def circle_cat(category):
|
||||
if category is None:
|
||||
return mark_safe('<span class="cat ' + Category.default_css_class + '" data-tooltip="' + Category.default_name + '"></span>')
|
||||
else:
|
||||
return mark_safe('<span class="cat ' + category.css_class() + '" data-tooltip="' + category.name + '"></span>')
|
@ -52,6 +52,11 @@ class CalendarDay:
|
||||
|
||||
def add_event(self, event):
|
||||
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)
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user