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 import template
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
from django.core.cache import cache
|
||||||
|
|
||||||
from agenda_culturel.models import Category
|
from agenda_culturel.models import Category
|
||||||
import colorsys
|
import colorsys
|
||||||
@ -67,59 +68,62 @@ def background_color_adjust_color(color, alpha=1):
|
|||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def css_categories():
|
def css_categories():
|
||||||
result = '<style type="text/css">'
|
result = cache.get('css_categories')
|
||||||
|
if not result: #
|
||||||
|
result = '<style type="text/css">'
|
||||||
|
|
||||||
cats = [
|
cats = [
|
||||||
{"color": c.color, "css_class": c.css_class()} for c in Category.objects.all()
|
{"color": c.color, "css_class": c.css_class()} for c in Category.objects.all()
|
||||||
]
|
]
|
||||||
cats.append(
|
cats.append(
|
||||||
{"color": Category.default_color, "css_class": Category.default_css_class}
|
{"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
|
|
||||||
)
|
)
|
||||||
result += "}"
|
|
||||||
|
|
||||||
result += "*:hover>." + c["css_class"] + " {"
|
for c in cats:
|
||||||
result += background_color_adjust_color(
|
result += "." + c["css_class"] + " {"
|
||||||
adjust_lightness_saturation(c["color"], 0.02, 1.0)
|
result += background_color_adjust_color(
|
||||||
)
|
adjust_lightness_saturation(c["color"], 0.2, 0.8), 0.8
|
||||||
result += "}"
|
)
|
||||||
|
result += "}"
|
||||||
|
|
||||||
result += "." + c["css_class"] + ".circ-cat, "
|
result += "*:hover>." + c["css_class"] + " {"
|
||||||
result += "form ." + c["css_class"] + ", "
|
result += background_color_adjust_color(
|
||||||
result += ".selected ." + c["css_class"] + " {"
|
adjust_lightness_saturation(c["color"], 0.02, 1.0)
|
||||||
result += background_color_adjust_color(c["color"])
|
)
|
||||||
result += "}"
|
result += "}"
|
||||||
|
|
||||||
result += "." + c["css_class"] + ".circ-cat.recurrent, "
|
result += "." + c["css_class"] + ".circ-cat, "
|
||||||
result += ".selected.recurrent ." + c["css_class"] + " {"
|
result += "form ." + c["css_class"] + ", "
|
||||||
result += "background: none;"
|
result += ".selected ." + c["css_class"] + " {"
|
||||||
result += "color: " + adjust_color(c["color"]) + ";"
|
result += background_color_adjust_color(c["color"])
|
||||||
result += "}"
|
result += "}"
|
||||||
|
|
||||||
result += "." + c["css_class"] + ".circ-cat:hover, "
|
result += "." + c["css_class"] + ".circ-cat.recurrent, "
|
||||||
result += "form ." + c["css_class"] + ":hover, "
|
result += ".selected.recurrent ." + c["css_class"] + " {"
|
||||||
result += "a.selected:hover ." + c["css_class"] + " {"
|
result += "background: none;"
|
||||||
result += background_color_adjust_color(
|
result += "color: " + adjust_color(c["color"]) + ";"
|
||||||
adjust_lightness_saturation(c["color"], 0.2, 1.2)
|
result += "}"
|
||||||
)
|
|
||||||
result += "}"
|
|
||||||
|
|
||||||
result += "." + c["css_class"] + ".circ-cat.recurrent:hover, "
|
result += "." + c["css_class"] + ".circ-cat:hover, "
|
||||||
result += ".selected.recurrent:hover ." + c["css_class"] + " {"
|
result += "form ." + c["css_class"] + ":hover, "
|
||||||
result += "background: none;"
|
result += "a.selected:hover ." + c["css_class"] + " {"
|
||||||
result += (
|
result += background_color_adjust_color(
|
||||||
"color: "
|
adjust_lightness_saturation(c["color"], 0.2, 1.2)
|
||||||
+ adjust_color(adjust_lightness_saturation(c["color"], 0.2, 1.2))
|
)
|
||||||
+ ";"
|
result += "}"
|
||||||
)
|
|
||||||
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)
|
return mark_safe(result)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user