diff --git a/lacommunaute/forum/views.py b/lacommunaute/forum/views.py index 191c7920..6439c0b2 100644 --- a/lacommunaute/forum/views.py +++ b/lacommunaute/forum/views.py @@ -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 @@ -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() @@ -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) diff --git a/lacommunaute/templates/forum/forum_documentation_category.html b/lacommunaute/templates/forum/forum_documentation_category.html index dd1f2eb7..9b89cbfc 100644 --- a/lacommunaute/templates/forum/forum_documentation_category.html +++ b/lacommunaute/templates/forum/forum_documentation_category.html @@ -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 %}