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;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.suggested-tags {
|
||||||
|
font-size: 80%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 992px) {
|
@media (min-width: 992px) {
|
||||||
@ -138,6 +141,7 @@ details[role="list"] summary + ul li.selected>a:hover {
|
|||||||
}
|
}
|
||||||
#filters .categories {
|
#filters .categories {
|
||||||
width: 50%;
|
width: 50%;
|
||||||
|
clear: both;
|
||||||
float: left;
|
float: left;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
line-height: 2em;
|
line-height: 2em;
|
||||||
@ -145,20 +149,17 @@ details[role="list"] summary + ul li.selected>a:hover {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#filters details {
|
#filters .filtres {
|
||||||
width: 25%;
|
width: 50%;
|
||||||
float: right;
|
float: right;
|
||||||
summary {
|
summary {
|
||||||
padding: 0.2em 0.4em;
|
padding: 0.2em 0.4em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#filters details.active {
|
|
||||||
width: 50%;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#filters details[open=""] {
|
#filters .filtres:has(details[open=""]) {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
transition: width 0.1s ease-in-out;
|
transition: width 0.1s ease-in-out;
|
||||||
display: block;
|
display: block;
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
{% show_legend filter=filter %}
|
{% show_legend filter=filter %}
|
||||||
</div>
|
</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">
|
<summary role="button" class="outline secondary">
|
||||||
{% if filter.is_active %}
|
{% if filter.is_active %}
|
||||||
<strong>Filtres : </strong>
|
<strong>Filtres : </strong>
|
||||||
@ -64,9 +65,14 @@
|
|||||||
<button type="submit">Appliquer le filtre</button>
|
<button type="submit">Appliquer le filtre</button>
|
||||||
</form>
|
</form>
|
||||||
</details>
|
</details>
|
||||||
|
<div class="suggested-tags">
|
||||||
|
{% show_suggested_tags filter=filter %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{% if noarticle == 0 %}
|
{% if noarticle == 0 %}
|
||||||
</article>
|
</article>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
from django import template
|
from django import template
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
from agenda_culturel.models import Tag
|
||||||
|
from .utils_extra import *
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
def t_button(tag, url, strike):
|
def t_button(tag, url, strike=False):
|
||||||
strike_class = " strike" if strike else ""
|
strike_class = " strike" if strike else ""
|
||||||
if not url is None:
|
if not url is None:
|
||||||
return mark_safe(
|
return mark_safe(
|
||||||
@ -42,3 +44,16 @@ def tag_button_link(tag):
|
|||||||
@register.filter
|
@register.filter
|
||||||
def tag_not_in_db(tag, tags):
|
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):
|
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):
|
def set_default_values(request):
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user