Ajout d'un symbole récurrent aux événements

Fix #105
This commit is contained in:
Jean-Marie Favreau 2024-04-23 21:53:15 +02:00
parent 3a09ad0127
commit e99a2e1cc0
8 changed files with 50 additions and 14 deletions

View File

@ -64,6 +64,11 @@ body>footer {
font-size: 80%;
}
.cat[data-tooltip]:not(a, button, input),
.recurrent span[data-tooltip] {
border: 0;
}
.action {
color: $primary-500;
@ -803,4 +808,4 @@ table .buttons {
width: 800px;
margin: 4em auto;
}
}
}

View File

@ -62,7 +62,7 @@
{% else %}
<ul>
{% for event in day.events %}
<li>{{ event.category | circle_cat }}
<li>{{ event.category | circle_cat:event.has_recurrences }}
{% if event.start_day == day.date and event.start_time %}
{{ event.start_time }}
{% endif %}

View File

@ -2,7 +2,7 @@
{% load cat_extra %}
{% load event_extra %}
<header>{{ event.category | small_cat }}
<header>{{ event.category | small_cat_recurrent:event.has_recurrences }}
{{ event|picto_status }}
<a href="{{ event.get_absolute_url }}">
{% if event.title_hl %}{{ event.title_hl | safe }}{% else %}{{ event.title }}{% endif %}</a></p>

View File

@ -20,7 +20,7 @@
{% endif %}
{% endif %}
{{ event.category | small_cat }}
{{ event.category | small_cat_recurrent:event.has_recurrences }}
{% if event.location %}<hgroup>{% endif %}
<h3>
{{ event|picto_status }}

View File

@ -7,7 +7,7 @@
<article>
{% include "agenda_culturel/ephemeris-inc.html" with event=event filter=filter %}
{{ event.category | small_cat }}
{{ event.category | small_cat_recurrent:event.has_recurrences }}
{% if event.location %}<hgroup>{% endif %}
<h2>
{{ event|picto_status }}

View File

@ -11,7 +11,7 @@
class="close"
data-target="event-{{ event.id }}"
onClick="toggleModal(event)"></a>
<h3>{{ event.category | small_cat }} {{ event|picto_status }} {{ event.title }}</h3>
<h3>{{ event.category|small_cat_recurrent:event.has_recurrences }} {{ event|picto_status }} {{ event.title }}</h3>
<p>
{% picto_from_name "map-pin" %}

View File

@ -7,7 +7,7 @@
<article>
<header>
{% include "agenda_culturel/ephemeris-inc.html" with event=event filter=filter %}
{{ event.category | small_cat }}
{{ event.category | small_cat_recurrent:event.has_recurrences }}
<h1>{{ event|picto_status }} {{ event.title }}</h1>
<p>
{% picto_from_name "calendar" %}

View File

@ -4,6 +4,7 @@ from django.utils.safestring import mark_safe
from agenda_culturel.models import Category
import statistics
import colorsys
from .utils_extra import *
register = template.Library()
@ -46,9 +47,11 @@ def adjust_lightness_saturation(hex_color, shift_lightness = 0.0, scale_saturati
return rgb_to_html([r, g, b])
def adjust_color(color, alpha = 1):
return color + ("0" + hex(int(alpha * 255))[2:])[-2:]
def background_color_adjust_color(color, alpha = 1):
result = " background-color: " + color + ("0" + hex(int(alpha * 255))[2:])[-2:] + ";"
result = " background-color: " + adjust_color(color, alpha) + ";"
if get_relative_luminance(color) < .5:
result += " color: #fff;"
else:
@ -79,38 +82,66 @@ def css_categories():
result += background_color_adjust_color(c["color"])
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: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: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>'
return mark_safe(result)
@register.filter
def small_cat(category, url=None, contrast=True, selected=True):
def small_cat(category, url=None, contrast=True, selected=True, recurrence=False):
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 ""
class_selected = " selected" if selected else ""
class_recurrence = " recurrent" if recurrence else ""
content = ('<span class="' + css_class + '">' + picto_from_name("repeat", name + ' [récurrent]') + '</span>') if recurrence else ('<span class="cat ' + css_class + '"></span>')
if url is None:
return mark_safe('<span class="small-cat' + class_contrast + class_selected + '" role="button"><span class="cat ' + css_class + '"></span> ' + name + "</span>")
return mark_safe('<span class="small-cat' + class_recurrence + class_contrast + class_selected + '" role="button">' + content + " " + name + "</span>")
else:
return mark_safe('<a class="small-cat' + class_contrast + class_selected + '" role="button" href="' + url + '"><span class="cat ' + css_class + '"></span> ' + name + "</a>")
return mark_safe('<a class="small-cat' + class_recurrence + class_contrast + class_selected + '" role="button" href="' + url + '">' + content + " " + name + "</a>")
@register.filter
def small_cat_no_selected(category, url=None):
return small_cat(category, url=url, selected=False)
@register.filter
def circle_cat(category):
def small_cat_recurrent(category, recurrence=False):
return small_cat(category, url=None, selected=True, recurrence=recurrence)
@register.filter
def circle_cat(category, recurrence=True):
if category is None:
return mark_safe('<span class="cat ' + Category.default_css_class + ' circ-cat" data-tooltip="' + Category.default_name + '"></span>')
c = Category.default_css_class
n = Category.default_name
else:
return mark_safe('<span class="cat ' + category.css_class() + ' circ-cat" data-tooltip="' + category.name + '"></span>')
c = category.css_class()
n = category.name
if recurrence:
return mark_safe('<span class="cat recurrent ' + c + ' circ-cat">' + picto_from_name("repeat", n + ' [récurrent]') + "</span>")
else:
return mark_safe('<span class="cat ' + c + ' circ-cat" data-tooltip="' + n + '"></span>')
@register.simple_tag