Début d'affichage de la liste des événements

This commit is contained in:
Jean-Marie Favreau 2023-10-30 22:46:47 +01:00
parent db7a8ca365
commit 4bb91184ef
5 changed files with 72 additions and 6 deletions

View File

@ -34,7 +34,7 @@ span.cat, span.mode {
} }
.mode { .mode {
background-color: #999; background-color: #CCC;
} }
a.mode:hover { a.mode:hover {
@ -64,3 +64,22 @@ a.mode:hover {
.cat a.close:hover { .cat a.close:hover {
background: #fff; background: #fff;
} }
.small-cat {
font-weight: bold;
text-decoration: none;
font-size: 80%;
display: inline-block;
padding: 0.1em 0.8em;
border-radius: .4em;
}
.warning-simple {
font-style: italic;
}
.warning {
background: #EEE;
padding: 1em;
border-radius: 1.5em;
}

View File

@ -5,6 +5,7 @@
{% load i18n %} {% load i18n %}
{% load cat_extra %} {% load cat_extra %}
{% load event_extra %}
{% block entete_header %} {% block entete_header %}
{% css_categories %} {% css_categories %}
@ -43,6 +44,33 @@
{% else %} {% else %}
{{ selected_mode | capfirst }} {{ selected_mode | capfirst }}
{% endif %}</h2> {% endif %}</h2>
{% if events %}
{% for date in dates %}
<h3>{{ date |date:"DATE_FORMAT" }}</h3>
{% with events_date=events|in_date:date %}
{% if events_date %}
<lu>
{% for event in events_date %}
<li>{% if category %}
{{ event.category | small_cat }}
{% else %}
{% url 'view_mode_cat' selected_mode.name event.category.pk as url_cat %}
{{ event.category | small_cat:url_cat }}
{% endif %} {{ event.title }}
</li>
{% endfor %}
</lu>
{% else %}
<p class="warning-simple">Aucun événement ce jour-là.</p>
{% endif %}
{% endwith %}
{% endfor %}
</ul>
{% else %}
<p class="warning">Aucun événement ne correspond à la recherche.</p>
{% endif %}
{% endblock %} {% endblock %}
</section> </section>
<footer id="tags"> <footer id="tags">

View File

@ -82,3 +82,10 @@ def css_categories():
result += '</style>' result += '</style>'
return mark_safe(result) return mark_safe(result)
@register.filter
def small_cat(category, url=None):
if url is None:
return mark_safe('<span class="small-cat selected ' + category.css_class() + '">' + category.name + "</span>")
else:
return mark_safe('<a class="small-cat selected ' + category.css_class() + '" href="' + url + '">' + category.name + "</a>")

View File

@ -0,0 +1,11 @@
from django import template
from django.utils.safestring import mark_safe
from agenda_culturel.models import Event
from django.db.models import Q
register = template.Library()
@register.filter
def in_date(event, date):
return event.filter((Q(start_day__lte=date) & Q(end_day__gte=date)) | (Q(end_day=None) & Q(start_day=date)))

View File

@ -8,6 +8,7 @@ from .models import Event, Category
from django.utils import timezone from django.utils import timezone
from enum import StrEnum from enum import StrEnum
from datetime import datetime, timedelta from datetime import datetime, timedelta
from django.db.models import Q
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.utils.translation import activate, get_language_info from django.utils.translation import activate, get_language_info
@ -60,17 +61,17 @@ def home(request):
def view_mode(request, mode): def view_mode(request, mode):
categories = Category.objects.all() categories = Category.objects.all()
dates = DisplayMode[mode].get_dates() dates = DisplayMode[mode].get_dates()
activate("fr") events = Event.objects.filter(Q(start_day__lte=dates[-1]) & Q(start_day__gte=dates[0])).order_by("start_day", "start_time")
context = {"modes": list(DisplayMode), "selected_mode": DisplayMode[mode], "categories": categories } context = {"modes": list(DisplayMode), "selected_mode": DisplayMode[mode], "categories": categories, "events": events, "dates": dates}
# TODO: select matching events
return render(request, 'agenda_culturel/page-events.html', context) return render(request, 'agenda_culturel/page-events.html', context)
def view_mode_cat(request, mode, cat_id): def view_mode_cat(request, mode, cat_id):
category = get_object_or_404(Category, pk=cat_id) category = get_object_or_404(Category, pk=cat_id)
categories = Category.objects.all() categories = Category.objects.all()
# TODO: select matching events dates = DisplayMode[mode].get_dates()
context = {"modes": list(DisplayMode), "selected_mode": DisplayMode[mode], "category": category, "categories": categories} events = Event.objects.filter(start_day__lte=dates[-1], start_day__gte=dates[0], category=category).order_by("start_day", "start_time")
context = {"modes": list(DisplayMode), "selected_mode": DisplayMode[mode], "category": category, "categories": categories, "events": events, "dates": dates}
return render(request, 'agenda_culturel/page-events.html', context) return render(request, 'agenda_culturel/page-events.html', context)