Correction du bouton reset de filtre en situation connectée

Fix #127
This commit is contained in:
Jean-Marie Favreau 2024-09-08 17:20:08 +02:00
parent bc106e2250
commit c0b1369f56
2 changed files with 26 additions and 1 deletions

View File

@ -32,7 +32,7 @@
<button type="submit">Appliquer le filtre</button>
</form>
</details>
{% if filter.is_active %}
{% if filter.is_resetable %}
<a href="{{ filter.get_url_without_filters }}" role="button">{% picto_from_name "x-circle" %} Supprimer le filtre</a>
{% endif %}

View File

@ -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