On affiche les tags principaux en suggestion sur les filtres
This commit is contained in:
parent
9933d87c04
commit
cece41b084
@ -130,6 +130,9 @@ details[role="list"] summary + ul li.selected>a:hover {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
.suggested-tags {
|
||||
font-size: 80%;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
@ -138,6 +141,7 @@ details[role="list"] summary + ul li.selected>a:hover {
|
||||
}
|
||||
#filters .categories {
|
||||
width: 50%;
|
||||
clear: both;
|
||||
float: left;
|
||||
text-align: left;
|
||||
line-height: 2em;
|
||||
@ -145,20 +149,17 @@ details[role="list"] summary + ul li.selected>a:hover {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
#filters details {
|
||||
width: 25%;
|
||||
#filters .filtres {
|
||||
width: 50%;
|
||||
float: right;
|
||||
summary {
|
||||
padding: 0.2em 0.4em;
|
||||
}
|
||||
}
|
||||
#filters details.active {
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#filters details[open=""] {
|
||||
#filters .filtres:has(details[open=""]) {
|
||||
width: 100%;
|
||||
transition: width 0.1s ease-in-out;
|
||||
display: block;
|
||||
|
@ -10,7 +10,8 @@
|
||||
{% show_legend filter=filter %}
|
||||
</div>
|
||||
|
||||
<details {% if filter.is_active %}class="active"{% endif %}>
|
||||
<div class="filtres">
|
||||
<details {% if filter.is_active %}class="active"{% endif %} {% if filter.form.errors %}open=""{% endif %}>
|
||||
<summary role="button" class="outline secondary">
|
||||
{% if filter.is_active %}
|
||||
<strong>Filtres : </strong>
|
||||
@ -64,8 +65,13 @@
|
||||
<button type="submit">Appliquer le filtre</button>
|
||||
</form>
|
||||
</details>
|
||||
<div class="clear"></div>
|
||||
<div class="suggested-tags">
|
||||
{% show_suggested_tags filter=filter %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
|
||||
|
||||
{% if noarticle == 0 %}
|
||||
</article>
|
||||
|
@ -1,11 +1,13 @@
|
||||
from django import template
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.urls import reverse_lazy
|
||||
from agenda_culturel.models import Tag
|
||||
from .utils_extra import *
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
def t_button(tag, url, strike):
|
||||
def t_button(tag, url, strike=False):
|
||||
strike_class = " strike" if strike else ""
|
||||
if not url is None:
|
||||
return mark_safe(
|
||||
@ -41,4 +43,17 @@ def tag_button_link(tag):
|
||||
|
||||
@register.filter
|
||||
def tag_not_in_db(tag, tags):
|
||||
return len([t for t in tags if t.name == tag]) == 0
|
||||
return len([t for t in tags if t.name == tag]) == 0
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def show_suggested_tags(filter):
|
||||
filter.form.full_clean()
|
||||
tags = Tag.objects.all().filter(principal=True).order_by("name")
|
||||
result = "Suggestion :"
|
||||
|
||||
for t in tags:
|
||||
if filter.tag_exists(t.name) and not filter.is_selected_tag(t.name):
|
||||
result += ' ' + t_button(t.name, filter.get_url_add_tag(t.name))
|
||||
|
||||
return mark_safe(result)
|
||||
|
@ -388,7 +388,20 @@ class EventFilter(django_filters.FilterSet):
|
||||
)
|
||||
|
||||
def is_selected(self, cat):
|
||||
return cat in self.form.cleaned_data["category"]
|
||||
return "category" in self.form.cleaned_data and cat in self.form.cleaned_data["category"]
|
||||
|
||||
def is_selected_tag(self, tag):
|
||||
return "tags" in self.form.cleaned_data and tag in self.form.cleaned_data["tags"]
|
||||
|
||||
def get_url_add_tag(self, tag, full_path = None):
|
||||
if full_path is None:
|
||||
full_path = self.request.get_full_path()
|
||||
|
||||
result = full_path + ('&' if '?' in full_path else '?') + 'tags=' + str(tag)
|
||||
return result
|
||||
|
||||
def tag_exists(self, tag):
|
||||
return tag in [t[0] for t in self.form.fields["tags"].choices]
|
||||
|
||||
def set_default_values(request):
|
||||
if request.user.is_authenticated:
|
||||
|
Loading…
x
Reference in New Issue
Block a user