Début d'affichage de la liste des événements
This commit is contained in:
parent
db7a8ca365
commit
4bb91184ef
@ -34,7 +34,7 @@ span.cat, span.mode {
|
||||
}
|
||||
|
||||
.mode {
|
||||
background-color: #999;
|
||||
background-color: #CCC;
|
||||
}
|
||||
|
||||
a.mode:hover {
|
||||
@ -63,4 +63,23 @@ a.mode:hover {
|
||||
}
|
||||
.cat a.close:hover {
|
||||
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;
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
{% load i18n %}
|
||||
|
||||
{% load cat_extra %}
|
||||
{% load event_extra %}
|
||||
|
||||
{% block entete_header %}
|
||||
{% css_categories %}
|
||||
@ -43,6 +44,33 @@
|
||||
{% else %}
|
||||
{{ selected_mode | capfirst }}
|
||||
{% 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 %}
|
||||
</section>
|
||||
<footer id="tags">
|
||||
|
@ -82,3 +82,10 @@ def css_categories():
|
||||
|
||||
result += '</style>'
|
||||
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>")
|
11
src/agenda_culturel/templatetags/event_extra.py
Normal file
11
src/agenda_culturel/templatetags/event_extra.py
Normal 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)))
|
@ -8,6 +8,7 @@ from .models import Event, Category
|
||||
from django.utils import timezone
|
||||
from enum import StrEnum
|
||||
from datetime import datetime, timedelta
|
||||
from django.db.models import Q
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import activate, get_language_info
|
||||
@ -60,17 +61,17 @@ def home(request):
|
||||
def view_mode(request, mode):
|
||||
categories = Category.objects.all()
|
||||
dates = DisplayMode[mode].get_dates()
|
||||
activate("fr")
|
||||
context = {"modes": list(DisplayMode), "selected_mode": DisplayMode[mode], "categories": categories }
|
||||
# TODO: select matching events
|
||||
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, "events": events, "dates": dates}
|
||||
return render(request, 'agenda_culturel/page-events.html', context)
|
||||
|
||||
|
||||
def view_mode_cat(request, mode, cat_id):
|
||||
category = get_object_or_404(Category, pk=cat_id)
|
||||
categories = Category.objects.all()
|
||||
# TODO: select matching events
|
||||
context = {"modes": list(DisplayMode), "selected_mode": DisplayMode[mode], "category": category, "categories": categories}
|
||||
dates = DisplayMode[mode].get_dates()
|
||||
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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user