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 }}">
<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>
{% if day.events %}
{% if resume %}
@ -38,7 +38,7 @@
</ul>
<footer>
<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" />
</svg></a>
</div>

View File

@ -3,7 +3,7 @@
<article class='ephemeris'>
{% if not event.end_day or event.start_day == event.end_day %}
{{ 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>
{% if event.start_time %}
<footer>
@ -13,13 +13,13 @@
{% else %}
du
{{ 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" %}
{{ event.start_day |date:"F" }}
{% endif %}</a><br />
au
{{ 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>
{% endif %}
</article>

View File

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

View File

@ -1,6 +1,21 @@
{% load cat_extra %}
{% load tag_extra %}
<article>
<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>
<form method="get" class="form django-form">
{% csrf_token %}<br />

View File

@ -33,14 +33,14 @@
<div class="navigation">
<div>
{% 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" />
</svg> précédent</a>
{% endwith %}
</div>
<div class="right">
{% 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" />
</svg></a>
{% endwith %}
@ -54,11 +54,15 @@
{% endfor %}
{% else %}
<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>
{% endif %}
</article>
{% endif %}
<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>
{% endblock %}

View File

@ -32,12 +32,12 @@
<header>
<div class="navigation">
<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" />
</svg> précédent</a>
</div>
<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" />
</svg></a>
</div>
@ -54,8 +54,8 @@
<footer>
{% if calendar.today_in_calendar %}
<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 'aujourdhui' %}?{{ filter.get_url }}">Aujourd'hui</a>
<a role="button" href="{% url 'cette_semaine' %}?{{ filter.get_url }}">Cette semaine</a>
{% endif %}
</footer>
</article>

View File

@ -36,12 +36,12 @@
<header>
<div class="navigation">
<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" />
</svg> précédente</a>
</div>
<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" />
</svg></a>
</div>
@ -55,11 +55,11 @@
<footer>
{% 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 %}
<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 %}
<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 %}
</footer>
</article>

View File

@ -85,7 +85,7 @@ def css_categories():
return mark_safe(result)
@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
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:
return mark_safe('<span class="cat ' + Category.default_css_class + '" data-tooltip="' + Category.default_name + '"></span>')
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
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.edit import CreateView, UpdateView, DeleteView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import QueryDict
from .forms import EventSubmissionModelForm
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")
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:
self.url = EventFilter.build_get_url(args[0])
else:
self.url = ""
def filter_queryset(self, queryset):
# TODO
return super().filter_queryset(queryset)
class Meta:
@ -178,16 +179,20 @@ class EventFilter(django_filters.FilterSet):
field_labels = { 'category': "Catégories", "tags": "Étiquettes" }
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 = "?"):
result = ""
for p in get:
if p in EventFilter.Meta.fields:
for v in get.getlist(p):
result += first if len(result) == 0 else "&"
result += str(p) + "=" + str(v)
return result
def get_categories(self):
return self.form.cleaned_data["category"]
def get_tags(self):
return self.form.cleaned_data["tags"]
def is_active(self):
return len(self.form.cleaned_data["category"]) != 0 or len(self.form.cleaned_data["tags"]) != 0
def home(request):
@ -200,7 +205,6 @@ def month_view(request, year = None, month = None):
if month is None:
month = now.month
filtering_url = EventFilter.build_get_url(request.GET)
filter = EventFilter(request.GET, queryset=Event.objects.all())
cmonth = CalendarMonth(year, month, filter)
@ -216,7 +220,6 @@ def week_view(request, year = None, week = None):
if week is None:
week = now.isocalendar()[1]
filtering_url = EventFilter.build_get_url(request.GET)
filter = EventFilter(request.GET, queryset=Event.objects.all())
cweek = CalendarWeek(year, week, filter)
@ -234,8 +237,6 @@ def day_view(request, year = None, month = None, day = None):
day = now.day
day = date(year, month, day)
filtering_url = EventFilter.build_get_url(request.GET)
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")