diff --git a/src/agenda_culturel/import_tasks/custom_extractors/lapucealoreille.py b/src/agenda_culturel/import_tasks/custom_extractors/lapucealoreille.py index ac1bcc5..e87395f 100644 --- a/src/agenda_culturel/import_tasks/custom_extractors/lapucealoreille.py +++ b/src/agenda_culturel/import_tasks/custom_extractors/lapucealoreille.py @@ -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, diff --git a/src/agenda_culturel/migrations/0075_alter_event_category_and_more.py b/src/agenda_culturel/migrations/0075_alter_event_category_and_more.py new file mode 100644 index 0000000..da212dc --- /dev/null +++ b/src/agenda_culturel/migrations/0075_alter_event_category_and_more.py @@ -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'), + ), + ] diff --git a/src/agenda_culturel/migrations/0076_alter_category_pictogram.py b/src/agenda_culturel/migrations/0076_alter_category_pictogram.py new file mode 100644 index 0000000..df2a141 --- /dev/null +++ b/src/agenda_culturel/migrations/0076_alter_category_pictogram.py @@ -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'), + ), + ] diff --git a/src/agenda_culturel/migrations/0077_category_position_alter_event_category_and_more.py b/src/agenda_culturel/migrations/0077_category_position_alter_event_category_and_more.py new file mode 100644 index 0000000..9da2493 --- /dev/null +++ b/src/agenda_culturel/migrations/0077_category_position_alter_event_category_and_more.py @@ -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'), + ), + ] diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index ffb7b52..87753a8 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -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: diff --git a/src/agenda_culturel/static/style.scss b/src/agenda_culturel/static/style.scss index c7e537e..7c03ce3 100644 --- a/src/agenda_culturel/static/style.scss +++ b/src/agenda_culturel/static/style.scss @@ -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; diff --git a/src/agenda_culturel/templatetags/cat_extra.py b/src/agenda_culturel/templatetags/cat_extra.py index c9099d5..b64f1a0 100644 --- a/src/agenda_culturel/templatetags/cat_extra.py +++ b/src/agenda_culturel/templatetags/cat_extra.py @@ -214,12 +214,17 @@ def circle_cat(category, recurrence=False): '' ) -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' - return mark_safe( + if category.pictogram: + return mark_safe( + '' + '' + category.name + '' + ) + else: + return mark_safe( '' ) @@ -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('
' + " ".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("
" + " ".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] ) + "
" )