From c0b1369f566b9c5583e0ad33c37086f284082fe8 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Sun, 8 Sep 2024 17:20:08 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20du=20bouton=20reset=20de=20filtre?= =?UTF-8?q?=20en=20situation=20connect=C3=A9e=20Fix=20#127?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/agenda_culturel/filter-inc.html | 2 +- src/agenda_culturel/views.py | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/agenda_culturel/templates/agenda_culturel/filter-inc.html b/src/agenda_culturel/templates/agenda_culturel/filter-inc.html index 8febc83..2b7d162 100644 --- a/src/agenda_culturel/templates/agenda_culturel/filter-inc.html +++ b/src/agenda_culturel/templates/agenda_culturel/filter-inc.html @@ -32,7 +32,7 @@ -{% if filter.is_active %} +{% if filter.is_resetable %} {% picto_from_name "x-circle" %} Supprimer le filtre {% endif %} diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 3dad4c8..44a7be4 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -285,6 +285,31 @@ class EventFilter(django_filters.FilterSet): else: return "" + + def is_resetable(self, only_categories=False): + if only_categories: + return len(self.get_cleaned_data("category")) != 0 + else: + if self.request.user.is_authenticated: + if ( + len(self.get_cleaned_data("status")) != 1 + or + self.get_cleaned_data("status")[0] != Event.STATUS.PUBLISHED + ): + return True + else: + if ( + len(self.get_cleaned_data("status")) != 0 + ): + return True + return ( + len(self.get_cleaned_data("category")) != 0 + or len(self.get_cleaned_data("tags")) != 0 + or len(self.get_cleaned_data("exclude_tags")) != 0 + or len(self.get_cleaned_data("recurrences")) != 0 + or len(self.get_cleaned_data("city")) != 0 + ) + def is_active(self, only_categories=False): if only_categories: return len(self.get_cleaned_data("category")) != 0