Amélioration de la zone des filtres
This commit is contained in:
parent
8666f51e76
commit
0c6ea62671
@ -106,6 +106,9 @@ details {
|
||||
}
|
||||
details summary[role="button"] {
|
||||
color: var(--primary-inverse);
|
||||
[role="button"] {
|
||||
margin: -0.2em 0;
|
||||
}
|
||||
}
|
||||
|
||||
details[role="list"] summary + ul li.selected>a{
|
||||
@ -118,6 +121,36 @@ details[role="list"] summary + ul li.selected>a:hover {
|
||||
color: var(--primary-inverse);
|
||||
}
|
||||
|
||||
|
||||
@media (min-width: 992px) {
|
||||
#filters .categories {
|
||||
width: 75%;
|
||||
float: left;
|
||||
}
|
||||
#filters details {
|
||||
width: 25%;
|
||||
float: right;
|
||||
summary {
|
||||
padding: 0.2em 0.4em;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#filters details[open=""] {
|
||||
width: 100%;
|
||||
transition: width 0.1s ease-in-out;
|
||||
display: block;
|
||||
summary {
|
||||
padding: var(--form-element-spacing-vertical) var(--form-element-spacing-horizontal);
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
}
|
||||
|
||||
#filters .clear {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
#main-nav {
|
||||
box-shadow: 0 1px 0 rgba(115, 130, 140, 0.2);
|
||||
}
|
||||
@ -136,6 +169,14 @@ span.small-cat {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.simple-button {
|
||||
@extend .small-cat;
|
||||
border-radius: 1em;
|
||||
font-size: 80%;
|
||||
margin-left: .5em;
|
||||
padding: .1em .5em;
|
||||
}
|
||||
|
||||
svg {
|
||||
vertical-align: -0.125em;
|
||||
}
|
||||
|
@ -2,38 +2,45 @@
|
||||
{% load tag_extra %}
|
||||
{% load utils_extra %}
|
||||
|
||||
|
||||
<article id="filters">
|
||||
<div>
|
||||
<div class="categories">
|
||||
{% show_legend filter=filter %}
|
||||
</div>
|
||||
|
||||
<details>
|
||||
<summary role="button" class="outline secondary">
|
||||
{% if filter.is_active %}
|
||||
Filtre :
|
||||
{% for c in filter.get_categories %}
|
||||
{{ c | small_cat }}
|
||||
{% endfor %}
|
||||
{% for t in filter.get_tags %}
|
||||
{{ t | tag_button }}
|
||||
{% endfor %}
|
||||
{% for t in filter.get_exclude_tags %}
|
||||
{{ t | tag_button_strike }}
|
||||
{% endfor %}
|
||||
{% for s in filter.get_status_names %}
|
||||
{{ s }}
|
||||
{% endfor %}
|
||||
{% for c in filter.get_cities %}
|
||||
{{ c }}
|
||||
{% endfor %}
|
||||
{{ filter.get_recurrence_filtering }}
|
||||
{% else %}
|
||||
Filtrer
|
||||
{% endif %}
|
||||
</summary>
|
||||
<form method="get" class="form django-form main-filter">
|
||||
{{ filter.form.as_p }}<br />
|
||||
<button type="submit">Appliquer le filtre</button>
|
||||
</form>
|
||||
</details>
|
||||
{% if filter.is_resetable %}
|
||||
<a href="{{ filter.get_url_without_filters }}" role="button">{% picto_from_name "x-circle" %} Supprimer le filtre</a>
|
||||
{% endif %}
|
||||
<summary role="button" class="outline secondary">
|
||||
{% if filter.is_active %}
|
||||
Autres filtres :
|
||||
{% for t in filter.get_tags %}
|
||||
{{ t | tag_button }}
|
||||
{% endfor %}
|
||||
{% for t in filter.get_exclude_tags %}
|
||||
{{ t | tag_button_strike }}
|
||||
{% endfor %}
|
||||
{% for s in filter.get_status_names %}
|
||||
{{ s }}
|
||||
{% endfor %}
|
||||
{% for c in filter.get_cities %}
|
||||
{{ c }}
|
||||
{% endfor %}
|
||||
{{ filter.get_recurrence_filtering }}
|
||||
{% else %}
|
||||
Autres filtres
|
||||
{% endif %}
|
||||
|
||||
{% if filter.is_resetable %}
|
||||
<a class="secondary" href="{{ filter.get_url_without_filters_only_cats }}" data-tooltip="Supprimer les filtres">{% picto_from_name "x-circle" %}</a>
|
||||
{% endif %}
|
||||
|
||||
</summary>
|
||||
<form method="get" class="form django-form main-filter">
|
||||
{{ filter.form.as_p }}
|
||||
<button type="submit">Appliquer le filtre</button>
|
||||
</form>
|
||||
</details>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
|
||||
</article>
|
||||
|
@ -22,12 +22,13 @@
|
||||
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
{% with cache_timeout=user.is_authenticated|yesno:"30,600" %}
|
||||
{% cache cache_timeout day user.is_authenticated day filter.to_str LANGUAGE_CODE %}
|
||||
|
||||
|
||||
|
||||
|
||||
{% include "agenda_culturel/filter-inc.html" with filter=filter %}
|
||||
|
||||
|
||||
@ -89,10 +90,10 @@
|
||||
<nav>
|
||||
<ul>
|
||||
{% for category in categories %}
|
||||
{% with category.0.name as idcat %}
|
||||
{% with category.0.pk|stringformat:"i" as idcat %}
|
||||
{% with filter.get_url_without_filters|add:"?category="|add:idcat as cat_url %}
|
||||
<li>
|
||||
<a class="small-cat contrast selected" role="button" href="{{ cat_url }}"><span class="cat {{ category.0.css_class }}"></span>{{ idcat }} : {{ category.1 }}</a>
|
||||
<a class="small-cat contrast selected" role="button" href="{{ cat_url }}"><span class="cat {{ category.0.css_class }}"></span>{{ category.0.name }} : {{ category.1 }}</a>
|
||||
</li>
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
|
@ -66,9 +66,6 @@
|
||||
</div>
|
||||
<div class="slider-button button-right hidden">{% picto_from_name "arrow-right" %}</div>
|
||||
</div>
|
||||
<div>
|
||||
Légende : {% show_legend filter=filter %}
|
||||
</div>
|
||||
|
||||
|
||||
<footer>
|
||||
|
@ -63,10 +63,6 @@
|
||||
</div>
|
||||
<div class="slider-button button-right hidden">{% picto_from_name "arrow-right" %}</div>
|
||||
</div>
|
||||
<div>
|
||||
Légende : {% show_legend filter=filter %}
|
||||
</div>
|
||||
|
||||
|
||||
<footer>
|
||||
|
||||
|
@ -211,9 +211,10 @@ def circle_cat(category, recurrence=False):
|
||||
)
|
||||
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def show_legend(filter):
|
||||
current_url = filter.get_url_without_filters()
|
||||
filter.form.full_clean()
|
||||
cats = Category.objects.all()
|
||||
if filter.is_active(only_categories=True):
|
||||
return mark_safe("<div>" +
|
||||
@ -221,18 +222,18 @@ def show_legend(filter):
|
||||
[
|
||||
small_cat(
|
||||
c,
|
||||
current_url + "?category=" + str(c.pk)
|
||||
filter.get_url_add_categories([c.pk])
|
||||
if not filter.is_selected(c)
|
||||
else None,
|
||||
else filter.get_url_remove_categories([c.pk]),
|
||||
contrast=filter.is_selected(c),
|
||||
)
|
||||
for c in cats
|
||||
]
|
||||
) + "</div>"
|
||||
) + ' <a class="simple-button secondary" data-tooltip="Toutes les catégories" href="' + filter.get_url_without_filters() + '" role="button">' + picto_from_name('x-circle') + ' toutes</a></div>'
|
||||
)
|
||||
else:
|
||||
return mark_safe("<div>" +
|
||||
" ".join(
|
||||
[small_cat(c, current_url + "?category=" + str(c.pk)) for c in cats]
|
||||
[small_cat(c, filter.get_url_add_categories([c.pk])) for c in cats]
|
||||
) + "</div>"
|
||||
)
|
||||
|
@ -31,6 +31,7 @@ from .forms import (
|
||||
CategorisationForm,
|
||||
EventAddPlaceForm,
|
||||
PlaceForm,
|
||||
MultipleHiddenInput
|
||||
)
|
||||
|
||||
from .models import (
|
||||
@ -195,7 +196,7 @@ class EventFilter(django_filters.FilterSet):
|
||||
field_name="category__id",
|
||||
to_field_name="id",
|
||||
queryset=Category.objects.all(),
|
||||
widget=CategoryCheckboxSelectMultiple,
|
||||
widget=MultipleHiddenInput,
|
||||
)
|
||||
|
||||
city = django_filters.MultipleChoiceFilter(
|
||||
@ -230,11 +231,47 @@ class EventFilter(django_filters.FilterSet):
|
||||
if isinstance(self.form.data, QueryDict):
|
||||
return self.form.data.urlencode()
|
||||
else:
|
||||
print(self.form.data)
|
||||
return ""
|
||||
|
||||
def get_url_without_filters(self):
|
||||
return self.request.get_full_path().split("?")[0]
|
||||
def get_full_url(self):
|
||||
return self.request.get_full_path()
|
||||
|
||||
def get_url_remove_categories(self, catpks, full_path = None):
|
||||
if full_path is None:
|
||||
full_path = self.request.get_full_path()
|
||||
|
||||
result = full_path
|
||||
for catpk in catpks:
|
||||
result = result.replace('category=' + str(catpk), '')
|
||||
result = result.replace('?&', '?')
|
||||
result = result.replace('&&', '&')
|
||||
return result
|
||||
|
||||
def get_url_add_categories(self, catpks, full_path = None):
|
||||
if full_path is None:
|
||||
full_path = self.request.get_full_path()
|
||||
|
||||
result = full_path
|
||||
for catpk in catpks:
|
||||
result = result + ('&' if '?' in full_path else '?') + 'category=' + str(catpk)
|
||||
return result
|
||||
|
||||
def get_url_without_filters_only_cats(self):
|
||||
return self.get_url_without_filters(True)
|
||||
|
||||
|
||||
def get_url_without_filters(self, only_categories=False):
|
||||
|
||||
if only_categories:
|
||||
# on repart d'une url sans option
|
||||
result = self.request.get_full_path().split("?")[0]
|
||||
# on ajoute toutes les catégories
|
||||
result = self.get_url_add_categories([c.pk for c in self.get_categories()], result)
|
||||
else:
|
||||
# on supprime toutes les catégories
|
||||
result = self.get_url_remove_categories([c.pk for c in self.get_categories()])
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def get_cleaned_data(self, name):
|
||||
@ -249,7 +286,7 @@ class EventFilter(django_filters.FilterSet):
|
||||
return self.get_cleaned_data("category")
|
||||
|
||||
def get_tags(self):
|
||||
return self.get_cleaned_data("cleaned_data")
|
||||
return self.get_cleaned_data("tags")
|
||||
|
||||
def get_exclude_tags(self):
|
||||
return self.get_cleaned_data("exclude_tags")
|
||||
@ -303,8 +340,7 @@ class EventFilter(django_filters.FilterSet):
|
||||
):
|
||||
return True
|
||||
return (
|
||||
len(self.get_cleaned_data("category")) != 0
|
||||
or len(self.get_cleaned_data("tags")) != 0
|
||||
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
|
||||
@ -319,8 +355,7 @@ class EventFilter(django_filters.FilterSet):
|
||||
):
|
||||
return True
|
||||
return (
|
||||
len(self.get_cleaned_data("category")) != 0
|
||||
or len(self.get_cleaned_data("tags")) != 0
|
||||
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
|
||||
@ -371,7 +406,8 @@ def month_view(request, year=None, month=None):
|
||||
if month is None:
|
||||
month = now.month
|
||||
|
||||
filter = EventFilter(request.GET, queryset=get_event_qs(request), request=request)
|
||||
request = EventFilter.set_default_values(request)
|
||||
filter = EventFilter(request.GET, get_event_qs(request), request=request)
|
||||
cmonth = CalendarMonth(year, month, filter)
|
||||
|
||||
context = {
|
||||
@ -392,7 +428,7 @@ def week_view(request, year=None, week=None, home=False):
|
||||
|
||||
|
||||
request = EventFilter.set_default_values(request)
|
||||
filter = EventFilter(request.GET, queryset=get_event_qs(request), request=request)
|
||||
filter = EventFilter(request.GET, get_event_qs(request), request=request)
|
||||
cweek = CalendarWeek(year, week, filter)
|
||||
|
||||
context = {"year": year, "week": week, "calendar": cweek, "filter": filter}
|
||||
|
Loading…
x
Reference in New Issue
Block a user