From 7b67550618596ba92bc07cb28cdec5cee860bc77 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Tue, 14 May 2024 17:57:33 +0200 Subject: [PATCH 1/2] (forum_conversation) make tags clickable --- .../forum_conversation/tests/tests_views.py | 14 ++++++++++++++ .../forum_conversation/partials/topic_tags.html | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lacommunaute/forum_conversation/tests/tests_views.py b/lacommunaute/forum_conversation/tests/tests_views.py index a75e1f869..019f62450 100644 --- a/lacommunaute/forum_conversation/tests/tests_views.py +++ b/lacommunaute/forum_conversation/tests/tests_views.py @@ -833,6 +833,20 @@ def test_template_name(self): response = self.client.get(self.url, **{"HTTP_HX_REQUEST": "true"}) self.assertTemplateUsed(response, "forum_conversation/topic_list.html") + def test_clickable_tags(self): + tag = Tag.objects.create(name="tag") + TopicFactory(with_post=True, forum=self.forum, with_tags=[tag.name]) + self.client.force_login(self.user) + + response = self.client.get(self.url) + self.assertContains( + response, + ( + f'{ tag.name }' + ), + ) + class NewsFeedTopicListViewTest(TestCase): @classmethod diff --git a/lacommunaute/templates/forum_conversation/partials/topic_tags.html b/lacommunaute/templates/forum_conversation/partials/topic_tags.html index 4fe3cbb23..4413eef06 100644 --- a/lacommunaute/templates/forum_conversation/partials/topic_tags.html +++ b/lacommunaute/templates/forum_conversation/partials/topic_tags.html @@ -1 +1,4 @@ -{% for tag in tags %}{{ tag }}{% endfor %} +{% load url_add_query %} +{% for tag in tags %} + {{ tag }} +{% endfor %} From 76be9c3795fd10985808a5bd13905aad0d318916 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Tue, 14 May 2024 18:19:53 +0200 Subject: [PATCH 2/2] (forum) minimalistic tag filtering in forum view, until it is refactored --- lacommunaute/forum/tests/tests_views.py | 10 ++++++++++ lacommunaute/forum/views.py | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/lacommunaute/forum/tests/tests_views.py b/lacommunaute/forum/tests/tests_views.py index 0e1bec01f..a0590af0d 100644 --- a/lacommunaute/forum/tests/tests_views.py +++ b/lacommunaute/forum/tests/tests_views.py @@ -411,3 +411,13 @@ def test_can_view_update_forum_link(self): self.user.save() response = self.client.get(self.url) self.assertContains(response, url) + + def test_filtered_queryset_on_tag(self): + tag = faker.word() + topic = TopicFactory(forum=self.forum, with_tags=[tag], with_post=True) + + response = self.client.get( + reverse("forum_extension:forum", kwargs={"pk": self.forum.pk, "slug": self.forum.slug}), {"tags": tag} + ) + self.assertContains(response, topic.subject) + self.assertNotContains(response, self.topic.subject) diff --git a/lacommunaute/forum/views.py b/lacommunaute/forum/views.py index dc2b5fc7c..540d83932 100644 --- a/lacommunaute/forum/views.py +++ b/lacommunaute/forum/views.py @@ -26,10 +26,18 @@ class ForumView(BaseForumView): paginate_by = settings.FORUM_TOPICS_NUMBER_PER_PAGE + def get_tags(self): + if not hasattr(self, "tags"): + self.tags = self.request.GET.get("tags", "").lower() + return self.tags + def get_queryset(self): forum = self.get_forum() qs = forum.topics.optimized_for_topics_list(self.request.user.id) + if self.get_tags(): + qs = qs.filter(tags__slug__in=self.get_tags().split(",")) + return qs def get_context_data(self, **kwargs):