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;
|
margin-top: -0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form.recent {
|
.form.recent, .form.main-filter {
|
||||||
#id_status>div {
|
#id_status>div {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-right: 2em;
|
margin-right: 2em;
|
||||||
|
@ -15,12 +15,15 @@
|
|||||||
{% for t in filter.get_exclude_tags %}
|
{% for t in filter.get_exclude_tags %}
|
||||||
{{ t | tag_button_strike }}
|
{{ t | tag_button_strike }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% for s in filter.get_status_names %}
|
||||||
|
{{ s }}
|
||||||
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
Filtrer
|
Filtrer
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</summary>
|
</summary>
|
||||||
<section>
|
<section>
|
||||||
<form method="get" class="form django-form">
|
<form method="get" class="form django-form main-filter">
|
||||||
{{ filter.form }}<br />
|
{{ filter.form }}<br />
|
||||||
<button type="submit">Appliquer le filtre</button><br />
|
<button type="submit">Appliquer le filtre</button><br />
|
||||||
</form>
|
</form>
|
||||||
|
@ -82,10 +82,20 @@ class EventFilter(django_filters.FilterSet):
|
|||||||
queryset=Category.objects.all(),
|
queryset=Category.objects.all(),
|
||||||
widget=CategoryCheckboxSelectMultiple)
|
widget=CategoryCheckboxSelectMultiple)
|
||||||
|
|
||||||
|
status = django_filters.MultipleChoiceFilter(label="Filtrer par status",
|
||||||
|
choices=Event.STATUS.choices,
|
||||||
|
field_name="status",
|
||||||
|
widget=forms.CheckboxSelectMultiple)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Event
|
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):
|
def get_url(self):
|
||||||
if isinstance(self.form.data, QueryDict):
|
if isinstance(self.form.data, QueryDict):
|
||||||
@ -106,10 +116,18 @@ class EventFilter(django_filters.FilterSet):
|
|||||||
def get_exclude_tags(self):
|
def get_exclude_tags(self):
|
||||||
return self.form.cleaned_data["exclude_tags"]
|
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):
|
def is_active(self, only_categories=False):
|
||||||
if only_categories:
|
if only_categories:
|
||||||
return len(self.form.cleaned_data["category"]) != 0
|
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
|
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):
|
def is_selected(self, cat):
|
||||||
|
Loading…
Reference in New Issue
Block a user