Mise en cache des CSS de styles
This commit is contained in:
parent
bf4bac340d
commit
9a0b62aa16
@ -1,5 +1,6 @@
|
||||
from django import template
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.core.cache import cache
|
||||
|
||||
from agenda_culturel.models import Category
|
||||
import colorsys
|
||||
@ -67,59 +68,62 @@ def background_color_adjust_color(color, alpha=1):
|
||||
|
||||
@register.simple_tag
|
||||
def css_categories():
|
||||
result = '<style type="text/css">'
|
||||
result = cache.get('css_categories')
|
||||
if not result: #
|
||||
result = '<style type="text/css">'
|
||||
|
||||
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"], 0.2, 0.8), 0.8
|
||||
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}
|
||||
)
|
||||
result += "}"
|
||||
|
||||
result += "*:hover>." + c["css_class"] + " {"
|
||||
result += background_color_adjust_color(
|
||||
adjust_lightness_saturation(c["color"], 0.02, 1.0)
|
||||
)
|
||||
result += "}"
|
||||
for c in cats:
|
||||
result += "." + c["css_class"] + " {"
|
||||
result += background_color_adjust_color(
|
||||
adjust_lightness_saturation(c["color"], 0.2, 0.8), 0.8
|
||||
)
|
||||
result += "}"
|
||||
|
||||
result += "." + c["css_class"] + ".circ-cat, "
|
||||
result += "form ." + c["css_class"] + ", "
|
||||
result += ".selected ." + c["css_class"] + " {"
|
||||
result += background_color_adjust_color(c["color"])
|
||||
result += "}"
|
||||
result += "*:hover>." + c["css_class"] + " {"
|
||||
result += background_color_adjust_color(
|
||||
adjust_lightness_saturation(c["color"], 0.02, 1.0)
|
||||
)
|
||||
result += "}"
|
||||
|
||||
result += "." + c["css_class"] + ".circ-cat.recurrent, "
|
||||
result += ".selected.recurrent ." + c["css_class"] + " {"
|
||||
result += "background: none;"
|
||||
result += "color: " + adjust_color(c["color"]) + ";"
|
||||
result += "}"
|
||||
result += "." + c["css_class"] + ".circ-cat, "
|
||||
result += "form ." + c["css_class"] + ", "
|
||||
result += ".selected ." + c["css_class"] + " {"
|
||||
result += background_color_adjust_color(c["color"])
|
||||
result += "}"
|
||||
|
||||
result += "." + c["css_class"] + ".circ-cat:hover, "
|
||||
result += "form ." + c["css_class"] + ":hover, "
|
||||
result += "a.selected:hover ." + c["css_class"] + " {"
|
||||
result += background_color_adjust_color(
|
||||
adjust_lightness_saturation(c["color"], 0.2, 1.2)
|
||||
)
|
||||
result += "}"
|
||||
result += "." + c["css_class"] + ".circ-cat.recurrent, "
|
||||
result += ".selected.recurrent ." + c["css_class"] + " {"
|
||||
result += "background: none;"
|
||||
result += "color: " + adjust_color(c["color"]) + ";"
|
||||
result += "}"
|
||||
|
||||
result += "." + c["css_class"] + ".circ-cat.recurrent:hover, "
|
||||
result += ".selected.recurrent:hover ." + c["css_class"] + " {"
|
||||
result += "background: none;"
|
||||
result += (
|
||||
"color: "
|
||||
+ adjust_color(adjust_lightness_saturation(c["color"], 0.2, 1.2))
|
||||
+ ";"
|
||||
)
|
||||
result += "}"
|
||||
result += "." + c["css_class"] + ".circ-cat:hover, "
|
||||
result += "form ." + c["css_class"] + ":hover, "
|
||||
result += "a.selected:hover ." + c["css_class"] + " {"
|
||||
result += background_color_adjust_color(
|
||||
adjust_lightness_saturation(c["color"], 0.2, 1.2)
|
||||
)
|
||||
result += "}"
|
||||
|
||||
result += "</style>"
|
||||
result += "." + c["css_class"] + ".circ-cat.recurrent:hover, "
|
||||
result += ".selected.recurrent:hover ." + c["css_class"] + " {"
|
||||
result += "background: none;"
|
||||
result += (
|
||||
"color: "
|
||||
+ adjust_color(adjust_lightness_saturation(c["color"], 0.2, 1.2))
|
||||
+ ";"
|
||||
)
|
||||
result += "}"
|
||||
|
||||
result += "</style>"
|
||||
cache.set('css_categories', result, 3600) # 1 hour
|
||||
return mark_safe(result)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user