Skip to content

Commit

Permalink
feat(tags): show tags user can filter on (tests in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Aug 13, 2024
1 parent 9e5d2d2 commit a0e88de
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
25 changes: 18 additions & 7 deletions lacommunaute/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.views.generic import CreateView, ListView, UpdateView
from machina.apps.forum.views import ForumView as BaseForumView
from machina.core.loading import get_class
from taggit.models import Tag

from lacommunaute.forum.enums import Kind as ForumKind
from lacommunaute.forum.forms import ForumForm
Expand Down Expand Up @@ -56,6 +57,12 @@ def get_descendants(self):

return qs.prefetch_related("tags")

def get_descendants_tags(self):
return Tag.objects.filter(
taggit_taggeditem_items__content_type=ContentType.objects.get_for_model(Forum),
taggit_taggeditem_items__object_id__in=self.get_forum().get_descendants().values_list("id", flat=True),
).distinct()

def get_context_data(self, **kwargs):
forum = self.get_forum()

Expand Down Expand Up @@ -85,13 +92,17 @@ def get_context_data(self, **kwargs):
)
context = context | self.get_topic_filter_context()

# vincentporte, overide the method to add the sub_forums, not testing permissions ^v^
context["sub_forums"] = ForumVisibilityContentTree.from_forums(
self.request.forum_permission_handler.forum_list_filter(
self.get_descendants(),
self.request.user,
),
)
if self.will_render_documentation_category_variant():
# vincentporte, overide the method to add the sub_forums, not testing permissions ^v^
# only in the documentation category which is public
context["sub_forums"] = ForumVisibilityContentTree.from_forums(
self.request.forum_permission_handler.forum_list_filter(
self.get_descendants(),
self.request.user,
),
)
context["sub_forums_tags"] = self.get_descendants_tags()
context["active_forum_tag_slug"] = self.request.GET.get("forum_tags") or None

if self.will_render_documentation_variant():
context["sibling_forums"] = forum.get_siblings(include_self=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{% extends "forum/forum_detail.html" %}
{% block forum_head_content %}
{{ block.super }}
{% if sub_forums_tags %}
{% include "forum/partials/forum_tags.html" with tags=sub_forums_tags only %}
{% endif %}
{% endblock forum_head_content %}
{% block subforum_list %}
<div class="row mt-4" id="documentation-category-subforums">
{% for node in sub_forums.top_nodes %}
Expand Down
16 changes: 16 additions & 0 deletions lacommunaute/templates/forum/partials/forum_tags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% load url_add_query %}
<div class="container-fluid d-flex justify-content-center c-box">
Filtrez par sous-catégorie :&nbsp;
{% for tag in tags %}
<a href="{% url_add_query request.path forum_tags=tag.slug %}">
{% if tag.slug == active_forum_tag_slug %}
{% include "partials/tag.html" with tag=tag highlight=1 only %}
{% else %}
{% include "partials/tag.html" with tag=tag only %}
{% endif %}
</a>&nbsp;
{% if forloop.last and active_forum_tag_slug %}
<a href="{{ request.path }}"><span class="tag bg-light text-muted"><i class="ri-close-circle-fill"></i> supprimer le filtre</span></a>
{% endif %}
{% endfor %}
</div>
2 changes: 1 addition & 1 deletion lacommunaute/templates/partials/tag.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<span class="tag bg-info-lighter text-info">{{ tag.name }}</span>
<span class="tag{% if highlight %} bg-info text-white{% else %} bg-info-lighter text-info{% endif %}">{{ tag.name }}</span>

0 comments on commit a0e88de

Please sign in to comment.