From 85db7ede8966d09ae8be9f359c9a02893b0a56e9 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Sun, 18 Feb 2024 22:33:31 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20d'un=20filtre=20de=20statut=20pour=20le?= =?UTF-8?q?s=20personnes=20connect=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agenda_culturel/static/style.scss | 2 +- .../templates/agenda_culturel/filter-inc.html | 5 ++++- src/agenda_culturel/views.py | 22 +++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/agenda_culturel/static/style.scss b/src/agenda_culturel/static/style.scss index 4690619..11f6da7 100644 --- a/src/agenda_culturel/static/style.scss +++ b/src/agenda_culturel/static/style.scss @@ -377,7 +377,7 @@ article#filters { margin-top: -0.5em; } -.form.recent { +.form.recent, .form.main-filter { #id_status>div { display: inline-block; margin-right: 2em; diff --git a/src/agenda_culturel/templates/agenda_culturel/filter-inc.html b/src/agenda_culturel/templates/agenda_culturel/filter-inc.html index c812b1b..7d3d97d 100644 --- a/src/agenda_culturel/templates/agenda_culturel/filter-inc.html +++ b/src/agenda_culturel/templates/agenda_culturel/filter-inc.html @@ -15,12 +15,15 @@ {% for t in filter.get_exclude_tags %} {{ t | tag_button_strike }} {% endfor %} + {% for s in filter.get_status_names %} + {{ s }} + {% endfor %} {% else %} Filtrer {% endif %}
-
+ {{ filter.form }}

diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 5732b5e..80b2a8b 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -82,10 +82,20 @@ class EventFilter(django_filters.FilterSet): queryset=Category.objects.all(), widget=CategoryCheckboxSelectMultiple) + status = django_filters.MultipleChoiceFilter(label="Filtrer par status", + choices=Event.STATUS.choices, + field_name="status", + widget=forms.CheckboxSelectMultiple) class Meta: model = Event - fields = ["category", "tags", "exclude_tags"] + fields = ["category", "tags", "exclude_tags", "status"] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + if not kwargs["request"].user.is_authenticated: + self.form.fields.pop("status") + def get_url(self): if isinstance(self.form.data, QueryDict): @@ -106,10 +116,18 @@ class EventFilter(django_filters.FilterSet): def get_exclude_tags(self): return self.form.cleaned_data["exclude_tags"] + def get_status(self): + return self.form.cleaned_data["status"] + + def get_status_names(self): + return [dict(Event.STATUS.choices)[s] for s in self.form.cleaned_data["status"]] + def is_active(self, only_categories=False): if only_categories: return len(self.form.cleaned_data["category"]) != 0 - else: + else: + if "status" in self.form.cleaned_data and len(self.form.cleaned_data["status"]) != 0: + return True return len(self.form.cleaned_data["category"]) != 0 or len(self.form.cleaned_data["tags"]) != 0 or len(self.form.cleaned_data["exclude_tags"]) != 0 def is_selected(self, cat):