Amélioration des légendes

This commit is contained in:
Jean-Marie Favreau 2024-09-14 22:22:20 +02:00
parent e2bc278ca9
commit 01387ff5b9
7 changed files with 92 additions and 9 deletions

View File

@ -14,7 +14,7 @@ class CExtractor(TwoStepsExtractor):
for e in events:
e_url = e.find("a")
if e_url:
if self.add_event_url(e_url["href"]):
self.add_event_url(e_url["href"])
def add_event_from_content(
self,

View File

@ -0,0 +1,24 @@
# Generated by Django 4.2.9 on 2024-09-14 13:18
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('agenda_culturel', '0074_category_pictogram_alter_event_category_and_more'),
]
operations = [
migrations.AlterField(
model_name='event',
name='category',
field=models.ForeignKey(default=1, help_text='Category of the event', null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='agenda_culturel.category', verbose_name='Category'),
),
migrations.AlterField(
model_name='recurrentimport',
name='defaultCategory',
field=models.ForeignKey(default=1, help_text='Category of each imported event', on_delete=django.db.models.deletion.SET_DEFAULT, to='agenda_culturel.category', verbose_name='Category'),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 4.2.9 on 2024-09-14 17:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('agenda_culturel', '0075_alter_event_category_and_more'),
]
operations = [
migrations.AlterField(
model_name='category',
name='pictogram',
field=models.FileField(blank=True, help_text='Pictogram of the category (svg format)', max_length=1024, null=True, upload_to='', verbose_name='Pictogram'),
),
]

View File

@ -0,0 +1,29 @@
# Generated by Django 4.2.9 on 2024-09-14 20:05
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('agenda_culturel', '0076_alter_category_pictogram'),
]
operations = [
migrations.AddField(
model_name='category',
name='position',
field=models.IntegerField(default=0, verbose_name='Position for ordering categories'),
),
migrations.AlterField(
model_name='event',
name='category',
field=models.ForeignKey(default=None, help_text='Category of the event', null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='agenda_culturel.category', verbose_name='Category'),
),
migrations.AlterField(
model_name='recurrentimport',
name='defaultCategory',
field=models.ForeignKey(default=None, help_text='Category of each imported event', on_delete=django.db.models.deletion.SET_DEFAULT, to='agenda_culturel.category', verbose_name='Category'),
),
]

View File

@ -107,14 +107,18 @@ class Category(models.Model):
null=True,
)
pictogram = models.ImageField(
pictogram = models.FileField(
verbose_name=_("Pictogram"),
help_text=_("Pictogram of the category"),
help_text=_("Pictogram of the category (svg format)"),
max_length=1024,
blank=True,
null=True,
)
position = models.IntegerField(
verbose_name=_("Position for ordering categories"), default=0
)
def save(self, *args, **kwargs):
if self.color is None:

View File

@ -170,7 +170,10 @@ details[role="list"] summary + ul li.selected>a:hover {
height: 2.6em;
width: 2.6em;
border-radius: 1.3em;
img {
width: 80%;
margin: .2em 0;
}
}
.reduced {
opacity: .3;

View File

@ -214,11 +214,16 @@ def circle_cat(category, recurrence=False):
'<span class="cat ' + c + ' circ-cat" data-tooltip="' + n + '"></span>'
)
def large_circle_cat(category, url, selected=True):
def legend_cat(category, url, selected=True):
c = category.css_class()
n = category.name
class_reduced = '' if selected else 'reduced'
if category.pictogram:
return mark_safe(
'<a href="' + url + '"<span class="cat ' + class_reduced + ' ' + c + ' circ-cat circ-large" data-tooltip="' + n + '">' + '<img src="' + category.pictogram.url + '" alt="' + category.name + '" /></span></a>'
)
else:
return mark_safe(
'<a href="' + url + '"<span class="cat ' + class_reduced + ' ' + c + ' circ-cat circ-large" data-tooltip="' + n + '"></span></a>'
)
@ -227,12 +232,12 @@ def large_circle_cat(category, url, selected=True):
@register.simple_tag
def show_legend(filter):
filter.form.full_clean()
cats = Category.objects.all()
cats = Category.objects.all().order_by("position")
if filter.is_active(only_categories=True):
return mark_safe('<div class="button-bar">' +
" ".join(
[
large_circle_cat(
legend_cat(
c,
filter.get_url_add_categories([c.pk])
if not filter.is_selected(c)
@ -246,6 +251,6 @@ def show_legend(filter):
else:
return mark_safe("<div>" +
" ".join(
[large_circle_cat(c, filter.get_url_add_categories([c.pk])) for c in cats]
[legend_cat(c, filter.get_url_add_categories([c.pk])) for c in cats]
) + "</div>"
)