on ajoute un affichage du fitre sélectionné

This commit is contained in:
Jean-Marie Favreau 2023-11-07 19:05:08 +01:00
parent d442502f5c
commit b4e119f7b6
10 changed files with 66 additions and 41 deletions

View File

@ -8,7 +8,7 @@
<article class="day{{ day|calendar_classes:fixed_style }}" id="{{ daytag }}"> <article class="day{{ day|calendar_classes:fixed_style }}" id="{{ daytag }}">
<header> <header>
<h2><a href="{{ day.date | url_day }}{{ filter.get_url }}">{{ day.date | date:"l j" }}</a></h2> <h2><a href="{{ day.date | url_day }}?{{ filter.get_url }}">{{ day.date | date:"l j" }}</a></h2>
</header> </header>
{% if day.events %} {% if day.events %}
{% if resume %} {% if resume %}
@ -38,7 +38,7 @@
</ul> </ul>
<footer> <footer>
<div class="buttons"> <div class="buttons">
<a href="{{ day.date | url_day }}{{ filter.get_url }}" role="button">Voir la journée <svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <a href="{{ day.date | url_day }}?{{ filter.get_url }}" role="button">Voir la journée <svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<use href="{% static 'images/feather-sprite.svg' %}#chevron-right" /> <use href="{% static 'images/feather-sprite.svg' %}#chevron-right" />
</svg></a> </svg></a>
</div> </div>

View File

@ -3,7 +3,7 @@
<article class='ephemeris'> <article class='ephemeris'>
{% if not event.end_day or event.start_day == event.end_day %} {% if not event.end_day or event.start_day == event.end_day %}
{{ event.start_day |date:"l" }}<br /> {{ event.start_day |date:"l" }}<br />
<a href="{{ event.start_day | url_day }}{{ filter.get_url }}"><span class="large">{{ event.start_day |date:"j" }}</span><br /> <a href="{{ event.start_day | url_day }}?{{ filter.get_url }}"><span class="large">{{ event.start_day |date:"j" }}</span><br />
{{ event.start_day |date:"F" }}</a> {{ event.start_day |date:"F" }}</a>
{% if event.start_time %} {% if event.start_time %}
<footer> <footer>
@ -13,13 +13,13 @@
{% else %} {% else %}
du du
{{ event.start_day |date:"D" }}<br /> {{ event.start_day |date:"D" }}<br />
<a href="{{ event.start_day | url_day }}{{ filter.get_url }}"><span class="large">{{ event.start_day |date:"j" }} </span> <a href="{{ event.start_day | url_day }}?{{ filter.get_url }}"><span class="large">{{ event.start_day |date:"j" }} </span>
{% if event.start_day|date:"F" != event.end_day|date:"F" %} {% if event.start_day|date:"F" != event.end_day|date:"F" %}
{{ event.start_day |date:"F" }} {{ event.start_day |date:"F" }}
{% endif %}</a><br /> {% endif %}</a><br />
au au
{{ event.start_day |date:"D" }} <br /> {{ event.start_day |date:"D" }} <br />
<a href="{{ event.end_day | url_day }}{{ filter.get_url }}"><span class="large">{{ event.end_day |date:"j" }}</span><br /> <a href="{{ event.end_day | url_day }}?{{ filter.get_url }}"><span class="large">{{ event.end_day |date:"j" }}</span><br />
{{ event.end_day |date:"F" }}</a> {{ event.end_day |date:"F" }}</a>
{% endif %} {% endif %}
</article> </article>

View File

@ -2,6 +2,7 @@
{% load cat_extra %} {% load cat_extra %}
{% load utils_extra %} {% load utils_extra %}
{% load event_extra %} {% load event_extra %}
{% load tag_extra %}
<article> <article>
{% if display in "in list by day" %} {% if display in "in list by day" %}
@ -101,7 +102,7 @@
{% if display == "modal" %} {% if display == "modal" %}
<p> <p>
{% for tag in event.tags %} {% for tag in event.tags %}
<a href="{% url 'view_tag' tag %}" role="button" class="small-cat">{{ tag }}</a> {{ tag | tag_button }}
{% endfor %} {% endfor %}
</p> </p>

View File

@ -1,6 +1,21 @@
{% load cat_extra %}
{% load tag_extra %}
<article> <article>
<details> <details>
<summary role="button">Filtres</summary> <summary role="button" class="contrast outline">
{% if filter.is_active %}
Filtres&nbsp;:
{% for c in filter.get_categories %}
{{ c | small_cat }}
{% endfor %}
{% for t in filter.get_tags %}
{{ t | tag_button }}
{% endfor %}
{% else %}
Filtrer
{% endif %}
</summary>
<section> <section>
<form method="get" class="form django-form"> <form method="get" class="form django-form">
{% csrf_token %}<br /> {% csrf_token %}<br />

View File

@ -33,14 +33,14 @@
<div class="navigation"> <div class="navigation">
<div> <div>
{% with day|shift_day:-1 as pred_day %} {% with day|shift_day:-1 as pred_day %}
<a role="button" href="{% url 'day_view' pred_day.year pred_day.month pred_day.day %}{{ filter.get_url }}"><svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <a role="button" href="{% url 'day_view' pred_day.year pred_day.month pred_day.day %}?{{ filter.get_url }}"><svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<use href="{% static 'images/feather-sprite.svg' %}#chevron-left" /> <use href="{% static 'images/feather-sprite.svg' %}#chevron-left" />
</svg> précédent</a> </svg> précédent</a>
{% endwith %} {% endwith %}
</div> </div>
<div class="right"> <div class="right">
{% with day|shift_day:1 as next_day %} {% with day|shift_day:1 as next_day %}
<a role="button" href="{% url 'day_view' next_day.year next_day.month next_day.day %}{{ filter.get_url }}">suivant <svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <a role="button" href="{% url 'day_view' next_day.year next_day.month next_day.day %}?{{ filter.get_url }}">suivant <svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<use href="{% static 'images/feather-sprite.svg' %}#chevron-right" /> <use href="{% static 'images/feather-sprite.svg' %}#chevron-right" />
</svg></a> </svg></a>
{% endwith %} {% endwith %}
@ -54,11 +54,15 @@
{% endfor %} {% endfor %}
{% else %} {% else %}
<article> <article>
{% if filter.is_active %}
<em>Il n'y a pas d'événement prévu à cette date correspondant au filtre sélectionné.</em>
{% else %}
<em>Il n'y a pas d'événement prévu à cette date.</em> <em>Il n'y a pas d'événement prévu à cette date.</em>
{% endif %}
</article> </article>
{% endif %} {% endif %}
<article> <article>
<a role="button" href="{% url 'week_view' day.year day|week %}{{ filter.get_url }}">Toute la semaine</a> <a role="button" href="{% url 'week_view' day.year day|week %}?{{ filter.get_url }}">Toute la semaine</a>
</article> </article>
{% endblock %} {% endblock %}

View File

@ -32,12 +32,12 @@
<header> <header>
<div class="navigation"> <div class="navigation">
<div> <div>
<a role="button" href="{% url 'month_view' calendar.previous_month.year calendar.previous_month.month %}{{ filter.get_url }}"><svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <a role="button" href="{% url 'month_view' calendar.previous_month.year calendar.previous_month.month %}?{{ filter.get_url }}"><svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<use href="{% static 'images/feather-sprite.svg' %}#chevron-left" /> <use href="{% static 'images/feather-sprite.svg' %}#chevron-left" />
</svg> précédent</a> </svg> précédent</a>
</div> </div>
<div class="right"> <div class="right">
<a role="button" href="{% url 'month_view' calendar.next_month.year calendar.next_month.month %}{{ filter.get_url }}">suivant <svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <a role="button" href="{% url 'month_view' calendar.next_month.year calendar.next_month.month %}?{{ filter.get_url }}">suivant <svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<use href="{% static 'images/feather-sprite.svg' %}#chevron-right" /> <use href="{% static 'images/feather-sprite.svg' %}#chevron-right" />
</svg></a> </svg></a>
</div> </div>
@ -54,8 +54,8 @@
<footer> <footer>
{% if calendar.today_in_calendar %} {% if calendar.today_in_calendar %}
<a role="button" href="{% url 'aujourdhui' %}{{ filter.get_url }}">Aujourd'hui</a> <a role="button" href="{% url 'aujourdhui' %}?{{ filter.get_url }}">Aujourd'hui</a>
<a role="button" href="{% url 'cette_semaine' %}{{ filter.get_url }}">Cette semaine</a> <a role="button" href="{% url 'cette_semaine' %}?{{ filter.get_url }}">Cette semaine</a>
{% endif %} {% endif %}
</footer> </footer>
</article> </article>

View File

@ -36,12 +36,12 @@
<header> <header>
<div class="navigation"> <div class="navigation">
<div> <div>
<a role="button" href="{% url 'week_view' calendar.previous_week.year calendar.previous_week|week %}{{ filter.get_url }}"><svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <a role="button" href="{% url 'week_view' calendar.previous_week.year calendar.previous_week|week %}?{{ filter.get_url }}"><svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<use href="{% static 'images/feather-sprite.svg' %}#chevron-left" /> <use href="{% static 'images/feather-sprite.svg' %}#chevron-left" />
</svg> précédente</a> </svg> précédente</a>
</div> </div>
<div class="right"> <div class="right">
<a role="button" href="{% url 'week_view' calendar.next_week.year calendar.next_week|week %}{{ filter.get_url }}">suivante <svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <a role="button" href="{% url 'week_view' calendar.next_week.year calendar.next_week|week %}?{{ filter.get_url }}">suivante <svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<use href="{% static 'images/feather-sprite.svg' %}#chevron-right" /> <use href="{% static 'images/feather-sprite.svg' %}#chevron-right" />
</svg></a> </svg></a>
</div> </div>
@ -55,11 +55,11 @@
<footer> <footer>
{% if calendar.today_in_calendar %} {% if calendar.today_in_calendar %}
<a role="button" href="{% url 'aujourdhui' %}{{ filter.get_url }}">Aujourd'hui</a> <a role="button" href="{% url 'aujourdhui' %}?{{ filter.get_url }}">Aujourd'hui</a>
{% endif %} {% endif %}
<a role="button" href="{% url 'month_view' calendar.firstdate.year calendar.firstdate.month %}{{ filter.get_url }}">{{ calendar.firstdate | date:"F o" }}</a> <a role="button" href="{% url 'month_view' calendar.firstdate.year calendar.firstdate.month %}?{{ filter.get_url }}">{{ calendar.firstdate | date:"F o" }}</a>
{% if calendar.firstdate.month != calendar.lastdate.month %} {% if calendar.firstdate.month != calendar.lastdate.month %}
<a role="button" href="{% url 'month_view' calendar.lastdate.year calendar.lastdate.month %}{{ filter.get_url }}">{{ calendar.lastdate | date:"F o" }}</a> <a role="button" href="{% url 'month_view' calendar.lastdate.year calendar.lastdate.month %}?{{ filter.get_url }}">{{ calendar.lastdate | date:"F o" }}</a>
{% endif %} {% endif %}
</footer> </footer>
</article> </article>

View File

@ -85,7 +85,7 @@ def css_categories():
return mark_safe(result) return mark_safe(result)
@register.filter @register.filter
def small_cat(category, url=None, contrast=True): def small_cat(category, url=None, contrast=True, close_url=None):
name = Category.default_name if category is None else category.name name = Category.default_name if category is None else category.name
css_class = Category.default_css_class if category is None else category.css_class() css_class = Category.default_css_class if category is None else category.css_class()
@ -101,4 +101,8 @@ def circle_cat(category):
if category is None: if category is None:
return mark_safe('<span class="cat ' + Category.default_css_class + '" data-tooltip="' + Category.default_name + '"></span>') return mark_safe('<span class="cat ' + Category.default_css_class + '" data-tooltip="' + Category.default_name + '"></span>')
else: else:
return mark_safe('<span class="cat ' + category.css_class() + '" data-tooltip="' + category.name + '"></span>') return mark_safe('<span class="cat ' + category.css_class() + '" data-tooltip="' + category.name + '"></span>')
@register.filter
def small_cat_close(category, close_url=None, contrast=True):
return small_cat(category, close_url=close_url, contrast=contrast)

View File

@ -21,4 +21,4 @@ def can_show_start_time(event):
@register.filter @register.filter
def need_complete_display(event, display): def need_complete_display(event, display):
return event.end_day and event.end_day != event.start_day and (event.start_time or event.end_time or display == "in list by day") return event.end_day and event.end_day != event.start_day and (event.start_time or event.end_time or display == "in list by day")

View File

@ -2,6 +2,8 @@ from django.shortcuts import render, get_object_or_404
from django.views.generic import ListView, DetailView, FormView from django.views.generic import ListView, DetailView, FormView
from django.views.generic.edit import CreateView, UpdateView, DeleteView from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import QueryDict
from .forms import EventSubmissionModelForm from .forms import EventSubmissionModelForm
from .celery import create_event_from_submission from .celery import create_event_from_submission
@ -164,12 +166,11 @@ class EventFilter(django_filters.FilterSet):
tags = django_filters.MultipleChoiceFilter(choices=[(t, t) for t in Event.get_all_tags()], lookup_expr='icontains', field_name="tags") tags = django_filters.MultipleChoiceFilter(choices=[(t, t) for t in Event.get_all_tags()], lookup_expr='icontains', field_name="tags")
category = django_filters.ModelMultipleChoiceFilter(field_name="category__id", to_field_name='id', queryset=Category.objects.all()) category = django_filters.ModelMultipleChoiceFilter(field_name="category__id", to_field_name='id', queryset=Category.objects.all())
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if len(args) > 0: def filter_queryset(self, queryset):
self.url = EventFilter.build_get_url(args[0]) # TODO
else: return super().filter_queryset(queryset)
self.url = ""
class Meta: class Meta:
@ -178,16 +179,20 @@ class EventFilter(django_filters.FilterSet):
field_labels = { 'category': "Catégories", "tags": "Étiquettes" } field_labels = { 'category': "Catégories", "tags": "Étiquettes" }
def get_url(self): def get_url(self):
return self.url if isinstance(self.form.data, QueryDict):
return self.form.data.urlencode()
else:
print(self.form.data)
return ""
def build_get_url(get, first = "?"): def get_categories(self):
result = "" return self.form.cleaned_data["category"]
for p in get:
if p in EventFilter.Meta.fields: def get_tags(self):
for v in get.getlist(p): return self.form.cleaned_data["tags"]
result += first if len(result) == 0 else "&"
result += str(p) + "=" + str(v) def is_active(self):
return result return len(self.form.cleaned_data["category"]) != 0 or len(self.form.cleaned_data["tags"]) != 0
def home(request): def home(request):
@ -200,7 +205,6 @@ def month_view(request, year = None, month = None):
if month is None: if month is None:
month = now.month month = now.month
filtering_url = EventFilter.build_get_url(request.GET)
filter = EventFilter(request.GET, queryset=Event.objects.all()) filter = EventFilter(request.GET, queryset=Event.objects.all())
cmonth = CalendarMonth(year, month, filter) cmonth = CalendarMonth(year, month, filter)
@ -216,7 +220,6 @@ def week_view(request, year = None, week = None):
if week is None: if week is None:
week = now.isocalendar()[1] week = now.isocalendar()[1]
filtering_url = EventFilter.build_get_url(request.GET)
filter = EventFilter(request.GET, queryset=Event.objects.all()) filter = EventFilter(request.GET, queryset=Event.objects.all())
cweek = CalendarWeek(year, week, filter) cweek = CalendarWeek(year, week, filter)
@ -234,8 +237,6 @@ def day_view(request, year = None, month = None, day = None):
day = now.day day = now.day
day = date(year, month, day) day = date(year, month, day)
filtering_url = EventFilter.build_get_url(request.GET)
filter = EventFilter(request.GET, Event.objects.all()) filter = EventFilter(request.GET, Event.objects.all())
events = filter.qs.filter(start_day__lte=day, start_day__gte=day).order_by("start_day", "start_time") events = filter.qs.filter(start_day__lte=day, start_day__gte=day).order_by("start_day", "start_time")