Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tags): rendre les tags clickables #623

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lacommunaute/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 8 additions & 0 deletions lacommunaute/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions lacommunaute/forum_conversation/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'<a href="{self.url}?tags={tag.slug}"><span class="badge badge-xs rounded-pill bg-info-lighter '
f'text-info">{ tag.name }</span></a>'
),
)


class NewsFeedTopicListViewTest(TestCase):
@classmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{% for tag in tags %}<span class="badge badge-xs rounded-pill bg-info-lighter text-info">{{ tag }}</span>{% endfor %}
{% load url_add_query %}
{% for tag in tags %}
<a href="{% url_add_query request.get_full_path tags=tag.slug %}"><span class="badge badge-xs rounded-pill bg-info-lighter text-info">{{ tag }}</span></a>
{% endfor %}
Loading