ajout d'un filtre de statut pour les personnes connectées
This commit is contained in:
parent
d65d99f9ed
commit
85db7ede89
@ -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;
|
||||
|
@ -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 %}
|
||||
</summary>
|
||||
<section>
|
||||
<form method="get" class="form django-form">
|
||||
<form method="get" class="form django-form main-filter">
|
||||
{{ filter.form }}<br />
|
||||
<button type="submit">Appliquer le filtre</button><br />
|
||||
</form>
|
||||
|
@ -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:
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user