Skip to content

Commit

Permalink
remove filtering on multiple tags, cause UI does not allow it, rename…
Browse files Browse the repository at this point in the history
… functions for more consistency
  • Loading branch information
vincentporte committed Sep 2, 2024
1 parent d4ef7ca commit ed5191a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@



<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="forum" hx-get="/forum/category-forum-[PK of Forum]/subs/?forum_tags=blues" hx-swap="outerHTML" hx-target="#subforums_area" id="filterforum-blues">Blues</button>
<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="forum" hx-get="/forum/category-forum-[PK of Forum]/subs/?forum_tag=blues" hx-swap="outerHTML" hx-target="#subforums_area" id="filterforum-blues">Blues</button>



Expand Down Expand Up @@ -71,13 +71,13 @@



<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="forum" hx-get="/forum/category-forum-[PK of Forum]/subs/?forum_tags=jazz" hx-swap="outerHTML" hx-target="#subforums_area" id="filterforum-jazz">Jazz</button>
<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="forum" hx-get="/forum/category-forum-[PK of Forum]/subs/?forum_tag=jazz" hx-swap="outerHTML" hx-target="#subforums_area" id="filterforum-jazz">Jazz</button>





<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="forum" hx-get="/forum/category-forum-[PK of Forum]/subs/?forum_tags=blues" hx-swap="outerHTML" hx-target="#subforums_area" id="filterforum-blues">Blues</button>
<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="forum" hx-get="/forum/category-forum-[PK of Forum]/subs/?forum_tag=blues" hx-swap="outerHTML" hx-target="#subforums_area" id="filterforum-blues">Blues</button>



Expand All @@ -102,13 +102,13 @@



<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="forum" hx-get="/forum/category-forum-[PK of Forum]/subs/?forum_tags=jazz" hx-swap="outerHTML" hx-target="#subforums_area" id="filterforum-jazz">Jazz</button>
<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="forum" hx-get="/forum/category-forum-[PK of Forum]/subs/?forum_tag=jazz" hx-swap="outerHTML" hx-target="#subforums_area" id="filterforum-jazz">Jazz</button>





<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="forum" hx-get="/forum/category-forum-[PK of Forum]/subs/?forum_tags=blues" hx-swap="outerHTML" hx-target="#subforums_area" id="filterforum-blues">Blues</button>
<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="forum" hx-get="/forum/category-forum-[PK of Forum]/subs/?forum_tag=blues" hx-swap="outerHTML" hx-target="#subforums_area" id="filterforum-blues">Blues</button>



Expand Down
6 changes: 3 additions & 3 deletions lacommunaute/forum/tests/__snapshots__/tests_views.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
</div>
'''
# ---
# name: TestDocumentationCategoryForumContent.test_show_subforum_tags[documentation_category_subforum_tags]
# name: TestDocumentationCategoryForumContent.test_show_subforum_tag[documentation_category_subforum_tag]
'''
<main class="s-main" id="main" role="main">

Expand Down Expand Up @@ -243,13 +243,13 @@



<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="forum" hx-get="/forum/test-forum-9999/subs/?forum_tags=tag1" hx-swap="outerHTML" hx-target="#subforums_area" id="filterforum-tag1">tag1</button>
<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="forum" hx-get="/forum/test-forum-9999/subs/?forum_tag=tag1" hx-swap="outerHTML" hx-target="#subforums_area" id="filterforum-tag1">tag1</button>





<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="forum" hx-get="/forum/test-forum-9999/subs/?forum_tags=tag2" hx-swap="outerHTML" hx-target="#subforums_area" id="filterforum-tag2">tag2</button>
<button class="tag bg-info-lighter text-info matomo-event" data-matomo-action="filter" data-matomo-category="engagement" data-matomo-option="forum" hx-get="/forum/test-forum-9999/subs/?forum_tag=tag2" hx-swap="outerHTML" hx-target="#subforums_area" id="filterforum-tag2">tag2</button>



Expand Down
4 changes: 2 additions & 2 deletions lacommunaute/forum/tests/test_subcategoryforum_listview.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_listview_filtering(client, db, documentation_forum, snapshot):
"forum_extension:subcategory_forums",
kwargs={"slug": documentation_forum.slug, "pk": documentation_forum.pk},
)
+ "?forum_tags=rock"
+ "?forum_tag=rock"
)
assert response.status_code == 200
content = parse_response_to_soup(
Expand All @@ -53,7 +53,7 @@ def test_listview_filtering(client, db, documentation_forum, snapshot):
"forum_extension:subcategory_forums",
kwargs={"slug": documentation_forum.slug, "pk": documentation_forum.pk},
)
+ "?forum_tags=jazz"
+ "?forum_tag=jazz"
)
assert response.status_code == 200
content = parse_response_to_soup(
Expand Down
16 changes: 7 additions & 9 deletions lacommunaute/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,21 +689,19 @@ def test_filter_subforums_on_tags(self, client, db):
category_forum.get_children()
)

# filter on first tag
response = client.get(category_forum.get_absolute_url() + f"?forum_tags={tags[0]}")
# filter on one tag
response = client.get(category_forum.get_absolute_url() + f"?forum_tag={tags[0]}")
assert response.status_code == 200
assert set([node.obj for node in response.context_data["sub_forums"].top_nodes]) == set(
[first_child, second_child]
)

# filter on multiple tags
response = client.get(category_forum.get_absolute_url() + f"?forum_tags={tags[1]},{tags[2]}")
# filtering on multiple tags is not supported yet
response = client.get(category_forum.get_absolute_url() + f"?forum_tag={tags[1]},{tags[2]}")
assert response.status_code == 200
assert set([node.obj for node in response.context_data["sub_forums"].top_nodes]) == set(
[second_child, third_child]
)
assert set([node.obj for node in response.context_data["sub_forums"].top_nodes]) == set([])

def test_show_subforum_tags(self, client, db, snapshot, reset_forum_sequence):
def test_show_subforum_tag(self, client, db, snapshot, reset_forum_sequence):
category_forum = CategoryForumFactory(with_public_perms=True, for_snapshot=True)
ForumFactory(parent=category_forum, with_public_perms=True, for_snapshot=True, name="Test-1")
ForumFactory(
Expand All @@ -718,7 +716,7 @@ def test_show_subforum_tags(self, client, db, snapshot, reset_forum_sequence):
assert response.status_code == 200

content = parse_response_to_soup(response, selector="main", replace_img_src=True)
assert str(content) == snapshot(name="documentation_category_subforum_tags")
assert str(content) == snapshot(name="documentation_category_subforum_tag")

def test_numqueries_on_tags(self, client, db, django_assert_num_queries):
category_forum = CategoryForumFactory(with_public_perms=True)
Expand Down
18 changes: 9 additions & 9 deletions lacommunaute/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ class SubCategoryForumListMixin:
def get_descendants(self):
qs = self.get_forum().get_descendants()

forum_tags = self.request.GET.get("forum_tags")
if forum_tags:
qs = qs.filter(tags__slug__in=forum_tags.split(","))
forum_tag = self.request.GET.get("forum_tag") or None
if forum_tag:
qs = qs.filter(tags__slug=forum_tag)

return qs.prefetch_related("tags")

def get_descendants_tags(self):
def get_tags_of_descendants(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 forum_tags_context(self):
def forum_tag_context(self):
return {
# TODO : remove permission management, though all forums are public in our case
"sub_forums": ForumVisibilityContentTree.from_forums(
Expand All @@ -52,8 +52,8 @@ def forum_tags_context(self):
self.request.user,
),
),
"sub_forums_tags": self.get_descendants_tags(),
"active_forum_tag_slug": self.request.GET.get("forum_tags") or None,
"tags_of_descendants": self.get_tags_of_descendants(),
"active_forum_tag_slug": self.request.GET.get("forum_tag") or None,
}


Expand Down Expand Up @@ -108,7 +108,7 @@ def get_context_data(self, **kwargs):
context = context | self.get_topic_filter_context()

if self.will_render_documentation_category_variant():
context = context | self.forum_tags_context()
context = context | self.forum_tag_context()

if self.will_render_documentation_variant():
context["sibling_forums"] = forum.get_siblings(include_self=True)
Expand All @@ -123,7 +123,7 @@ class SubCategoryForumListView(BaseForumView, SubCategoryForumListMixin):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context = context | self.forum_tags_context()
context = context | self.forum_tag_context()
return context


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "forum/forum_detail.html" %}
{% block subforum_list %}
{% include "forum/partials/subcategory_forum_list.html" with forum=forum sub_forums=sub_forums sub_forums_tags=sub_forums_tags active_forum_tag_slug=active_forum_tag_slug only %}
{% include "forum/partials/subcategory_forum_list.html" with forum=forum sub_forums=sub_forums tags_of_descendants=tags_of_descendants active_forum_tag_slug=active_forum_tag_slug only %}
{% endblock subforum_list %}
{% block forum_foot_content %}
{% if user.is_superuser %}
Expand Down
2 changes: 1 addition & 1 deletion lacommunaute/templates/forum/partials/forum_tags.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<button id="filterforum-{{ tag.slug }}"
hx-target="#subforums_area"
hx-swap="outerHTML"
hx-get="{% url 'forum_extension:subcategory_forums' forum.slug forum.pk %}?forum_tags={{ tag.slug }}"
hx-get="{% url 'forum_extension:subcategory_forums' forum.slug forum.pk %}?forum_tag={{ tag.slug }}"
class="tag bg-info-lighter text-info matomo-event"
data-matomo-category="engagement"
data-matomo-action="filter"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div id="subforums_area" class="container-fluid">
{% if sub_forums_tags %}
{% if tags_of_descendants %}
<div class="c-box">
<div class="container-fluid d-flex justify-content-center mb-3">Afficher les fiches contenant l'étiquette</div>
<div class="container-fluid d-flex justify-content-center">
{% include "forum/partials/forum_tags.html" with forum=forum tags=sub_forums_tags active_forum_tag_slug=active_forum_tag_slug only %}
{% include "forum/partials/forum_tags.html" with forum=forum tags=tags_of_descendants active_forum_tag_slug=active_forum_tag_slug only %}
</div>
</div>
{% endif %}
Expand Down

0 comments on commit ed5191a

Please sign in to comment.