ajout d'un moyen de voir les tags

This commit is contained in:
Jean-Marie Favreau 2023-11-04 16:44:03 +01:00
parent 58e4545ee1
commit 7dbdb824af
7 changed files with 84 additions and 2 deletions

View File

@ -28,7 +28,7 @@
<p>{{ event.category | small_cat }}</p> <p>{{ event.category | small_cat }}</p>
<p> <p>
{% for tag in event.tags %} {% for tag in event.tags %}
<a href="" role="button" class="small-cat">{{ tag }}</a> <a href="{% url 'view_tag' tag %}" role="button" class="small-cat">{{ tag }}</a>
{% endfor %} {% endfor %}
</p> </p>
</footer> </footer>

View File

@ -96,7 +96,7 @@
{% endif %} </p> {% endif %} </p>
<p> <p>
{% for tag in event.tags %} {% for tag in event.tags %}
<a href="" role="button" class="small-cat">{{ tag }}</a> <a href="{% url 'view_tag' tag %}" role="button" class="small-cat">{{ tag }}</a>
{% endfor %} {% endfor %}
</p> </p>
</footer> </footer>

View File

@ -57,6 +57,7 @@
<footer class="container"> <footer class="container">
<div class="grid"> <div class="grid">
<ul> <ul>
<li><a href="{% url 'view_all_tags' %}">Toutes les étiquettes</a></li>
<li>À propos</li> <li>À propos</li>
</ul> </ul>
<ul> <ul>

View File

@ -0,0 +1,41 @@
{% extends "agenda_culturel/page.html" %}
{% block title %}Étiquette {{ tag }}{% endblock %}
{% load cat_extra %}
{% block content %}
<h1>Étiquette <em>{{ tag }}</em></h1>
{% for event in events %}
<article>
<h3>
{% if not event.end_day and event.start_time %}{{ event.start_time }}{% endif %}
<a href="{{ event.get_absolute_url }}">{{ event.title }}</a></h3>
<ul>
<li>Début&nbsp;: {{ event.start_day }} {% if event.start_time %} à {{ event.start_time }}{% endif %}</li>
{% if event.end_day or event.end_time %}
<li>Fin&nbsp;:
{% if event.end_day %}{{ event.end_day }}{% endif %}
{% if event.end_time %}{{ event.end_time }}{% endif %}
</li>
{% endif %}
</ul>
<p>{{ event.description |truncatewords:20 }}</p>
<footer>
<p>{{ event.category | small_cat }}</p>
<p>
{% for tag in event.tags %}
<a href="{% url 'view_tag' tag %}" role="button" class="small-cat">{{ tag }}</a>
{% endfor %}
</p>
</footer>
</article>
{% endfor %}
{% endblock %}

View File

@ -0,0 +1,18 @@
{% extends "agenda_culturel/page.html" %}
{% block title %}Toutes les étiquettes{% endblock %}
{% load cat_extra %}
{% block content %}
<h1>Toutes les étiquettes</h1>
<p>Liste de toutes les étiquettes utilisées par les événements référencés&nbsp;:</p>
<div>
{% for tag in tags %}
<a href="{% url 'view_tag' tag %}" role="button" class="small-cat">{{ tag }}</a>
{% endfor %}
</div>
{% endblock %}

View File

@ -13,6 +13,8 @@ urlpatterns = [
path("", home, name="home"), path("", home, name="home"),
re_path(r'^(?P<mode>' + modes + ')/$', view_mode, name='view_mode'), re_path(r'^(?P<mode>' + modes + ')/$', view_mode, name='view_mode'),
re_path(r'^(?P<mode>' + modes + ')/(?P<cat_id>\d+)/$', view_mode_cat, name='view_mode_cat'), re_path(r'^(?P<mode>' + modes + ')/(?P<cat_id>\d+)/$', view_mode_cat, name='view_mode_cat'),
path("tag/<t>/", view_tag, name='view_tag'),
path("tags/", tag_list, name='view_all_tags'),
path("events/", event_list, name='view_all_events'), path("events/", event_list, name='view_all_events'),
path("event/<int:pk>-<extra>", EventDetailView.as_view(), name="view_event"), path("event/<int:pk>-<extra>", EventDetailView.as_view(), name="view_event"),
path("importer", EventSubmissionFormView.as_view(), name="event_import_form"), path("importer", EventSubmissionFormView.as_view(), name="event_import_form"),

View File

@ -16,6 +16,7 @@ import django_filters
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
import unicodedata
class DisplayMode(StrEnum): class DisplayMode(StrEnum):
@ -80,6 +81,25 @@ def view_mode_cat(request, mode, cat_id):
return render(request, 'agenda_culturel/page-events.html', context) return render(request, 'agenda_culturel/page-events.html', context)
def view_tag(request, t):
events = Event.objects.filter(tags__contains=[t]).order_by("start_day", "start_time")
context = {"tag": t, "events": events}
return render(request, 'agenda_culturel/tag.html', context)
def tag_list(request):
def remove_accents(input_str):
nfkd_form = unicodedata.normalize('NFKD', input_str)
return u"".join([c for c in nfkd_form if not unicodedata.combining(c)])
tags = list(Event.objects.values_list('tags', flat = True))
uniq_tags = set()
for t in tags:
uniq_tags = uniq_tags | set(t)
context = {"tags": sorted(list(uniq_tags), key=lambda x: remove_accents(x).lower())}
return render(request, 'agenda_culturel/tags.html', context)
class EventDetailView(DetailView): class EventDetailView(DetailView):
model = Event model = Event
template_name = "agenda_culturel/event.html" template_name = "agenda_culturel/event.html"