Skip to content

Commit

Permalink
feat(tags): afficher les Tags dans la liste des fiches pratiques d'un…
Browse files Browse the repository at this point in the history
…e categorie (#751)

## Description

🎸 Rendre visible les `Tag` dans la liste des `Forum` d'une catégorie de
documentation

## Type de changement

🎢 Nouvelle fonctionnalité (changement non cassant qui ajoute une
fonctionnalité).
🎨 changement d'UI


suite de #750 

### Captures d'écran (optionnel)

`Forum List`


![image](https://github.com/user-attachments/assets/274ce7bd-bc76-4b6d-9d35-fcb078fdb9cf)
  • Loading branch information
vincentporte committed Aug 26, 2024
1 parent eb6683a commit ed005b7
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 159 deletions.
243 changes: 111 additions & 132 deletions lacommunaute/forum/tests/__snapshots__/tests_views.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@

<div class="card-body pb-0">
<p class="h3 lh-base">Test Forum</p>

<div class="mt-3">Test description</div>
</div>
<div class="card-footer text-end">
Expand All @@ -176,6 +177,116 @@
</div>
'''
# ---
# name: TestDocumentationCategoryForumContent.test_show_subforum_tags[documentation_category_subforum_tags]
'''
<main class="s-main" id="main" role="main">





<div class="container">
<nav aria-label="Fil d'ariane" class="c-breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">Retourner vers</li>
<li class="breadcrumb-item">

<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="documentation_breadcrumb" href="/documentation/">Documentation</a>

</li>


</ol>
</nav>
</div>





<section class="s-title-01 mt-lg-5">
<div class="s-title-01__container container">
<div class="s-title-01__row row">
<div class="s-title-01__col col-12">
<h1>Test Forum</h1>

<h2 class="mt-3">Test description</h2>
</div>
</div>
</div>
</section>
<section class="s-section">
<div class="s-section__container container">


<div class="s-section__row row">
<div class="col-12">
<article class="textarea_cms_md"><p>Test description</p></article>
</div>
</div>


</div>
</section>

<section class="s-section">
<div class="s-section__container container">
<div class="s-section__row row">
<div class="s-section__col col-12">

<div class="row mt-4" id="documentation-category-subforums">

<div class="col-12 col-md-4 mb-3 mb-md-5">
<div class="card c-card has-one-link-inside h-100">

<div class="card-body pb-0">
<p class="h3 lh-base">Test-1</p>

<div class="mt-3">Test description</div>
</div>
<div class="card-footer text-end">
<a class="btn btn-sm btn-ico btn-link stretched-link matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="fiches_techniques" href="/forum/test-1-10000/">
<i class="ri-arrow-right-line ri-lg"></i>
</a>
</div>
</div>
</div>

<div class="col-12 col-md-4 mb-3 mb-md-5">
<div class="card c-card has-one-link-inside h-100">

<div class="card-header card-header-thumbnail rounded">
<img alt="Test-2" class="img-fitcover img-fluid" loading="lazy" src="[img src]"/>
</div>

<div class="card-body pb-0">
<p class="h3 lh-base">Test-2</p>
<div><span class="tag bg-info-lighter text-info">tag1</span><span class="tag bg-info-lighter text-info">tag2</span></div>
<div class="mt-3">Test description</div>
</div>
<div class="card-footer text-end">
<a class="btn btn-sm btn-ico btn-link stretched-link matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="fiches_techniques" href="/forum/test-2-10001/">
<i class="ri-arrow-right-line ri-lg"></i>
</a>
</div>
</div>
</div>

</div>

</div>
</div>
</div>
</section>






</main>
'''
# ---
# name: TestDocumentationForumContent.test_documentation_forum_header_content[template_documentation_link_to_parent]
'<a class="matomo-event h3 text-decoration-none d-inline-block" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="forum" href="/forum/parent-forum-9999/">Les autres fiches du thème Parent-Forum</a>'
# ---
Expand Down Expand Up @@ -332,51 +443,6 @@
</div>
'''
# ---
# name: TestForumViewContent.test_upvotes_actions[upvotes_actions_anonymous]
'''
<div class="d-inline-block" id="upvotesarea10000">


<a class="btn btn-sm btn-ico btn-link btn-secondary px-2" data-bs-placement="top" data-bs-toggle="tooltip" href="/inclusion_connect/authorize?next=%2Fforum%2Ftest-forum-forum-[PK of Forum]%2F%23[PK of Forum]" rel="nofollow" title="Connectez-vous pour sauvegarder">
<i aria-hidden="true" class="ri-bookmark-line me-1"></i><span>0</span>
</a>


</div>
'''
# ---
# name: TestForumViewContent.test_upvotes_actions[upvotes_actions_authenticated]
'''
<div class="d-inline-block" id="upvotesarea10000">


<form hx-post="/upvote/forum/" hx-swap="outerHTML" hx-target="#upvotesarea10000" id="upvote-button10000">
<input name="pk" type="hidden" value="10000"/>
<button class="btn btn-sm btn-ico btn-secondary matomo-event px-2" data-matomo-action="upvote" data-matomo-category="engagement" data-matomo-option="post" title="Sauvegarder" type="submit">
<i aria-hidden="true" class="ri-bookmark-line me-1"></i><span>0</span>
</button>
</form>


</div>
'''
# ---
# name: TestForumViewContent.test_upvotes_actions[upvotes_actions_upvoted]
'''
<div class="d-inline-block" id="upvotesarea10000">


<form hx-post="/upvote/forum/" hx-swap="outerHTML" hx-target="#upvotesarea10000" id="upvote-button10000">
<input name="pk" type="hidden" value="10000"/>
<button class="btn btn-sm btn-ico btn-secondary matomo-event px-2" data-matomo-action="upvote" data-matomo-category="engagement" data-matomo-option="post" title="Sauvegarder" type="submit">
<i aria-hidden="true" class="ri-bookmark-fill me-1"></i><span>1</span>
</button>
</form>


</div>
'''
# ---
# name: TestForumViewContent.test_upvotes_counts[0-False][upvotes_counts_0]
'''
<div class="d-inline-block" id="upvotesarea10000">
Expand Down Expand Up @@ -416,19 +482,6 @@
</form>


</div>
'''
# ---
# name: TestForumViewContent.test_upvotes_counts[0][upvotes_counts_0]
'''
<div class="d-inline-block" id="upvotesarea10000">


<a class="btn btn-sm btn-ico btn-link btn-secondary px-2" data-bs-placement="top" data-bs-toggle="tooltip" href="/inclusion_connect/authorize?next=%2Fforum%2Ftest-forum-forum-[PK of Forum]%2F%23[PK of Forum]" rel="nofollow" title="Connectez-vous pour sauvegarder">
<i aria-hidden="true" class="ri-bookmark-line me-1"></i><span>0</span>
</a>


</div>
'''
# ---
Expand Down Expand Up @@ -471,19 +524,6 @@
</form>


</div>
'''
# ---
# name: TestForumViewContent.test_upvotes_counts[1][upvotes_counts_1]
'''
<div class="d-inline-block" id="upvotesarea10000">


<a class="btn btn-sm btn-ico btn-link btn-secondary px-2" data-bs-placement="top" data-bs-toggle="tooltip" href="/inclusion_connect/authorize?next=%2Fforum%2Ftest-forum-forum-[PK of Forum]%2F%23[PK of Forum]" rel="nofollow" title="Connectez-vous pour sauvegarder">
<i aria-hidden="true" class="ri-bookmark-line me-1"></i><span>1</span>
</a>


</div>
'''
# ---
Expand Down Expand Up @@ -526,67 +566,6 @@
</form>


</div>
'''
# ---
# name: TestForumViewContent.test_upvotes_counts[2][upvotes_counts_2]
'''
<div class="d-inline-block" id="upvotesarea10000">


<a class="btn btn-sm btn-ico btn-link btn-secondary px-2" data-bs-placement="top" data-bs-toggle="tooltip" href="/inclusion_connect/authorize?next=%2Fforum%2Ftest-forum-forum-[PK of Forum]%2F%23[PK of Forum]" rel="nofollow" title="Connectez-vous pour sauvegarder">
<i aria-hidden="true" class="ri-bookmark-line me-1"></i><span>2</span>
</a>


</div>
'''
# ---
# name: TestForumViewContent.test_upvotes_counts[upvotes_counts_0]
'''
<div class="d-inline-block" id="upvotesarea10000">


<form hx-post="/upvote/forum/" hx-swap="outerHTML" hx-target="#upvotesarea10000" id="upvote-button10000">
<input name="pk" type="hidden" value="10000"/>
<button class="btn btn-sm btn-ico btn-secondary matomo-event px-2" data-matomo-action="upvote" data-matomo-category="engagement" data-matomo-option="post" title="Sauvegarder" type="submit">
<i aria-hidden="true" class="ri-bookmark-line me-1"></i><span>0</span>
</button>
</form>


</div>
'''
# ---
# name: TestForumViewContent.test_upvotes_counts[upvotes_counts_1]
'''
<div class="d-inline-block" id="upvotesarea10000">


<form hx-post="/upvote/forum/" hx-swap="outerHTML" hx-target="#upvotesarea10000" id="upvote-button10000">
<input name="pk" type="hidden" value="10000"/>
<button class="btn btn-sm btn-ico btn-secondary matomo-event px-2" data-matomo-action="upvote" data-matomo-category="engagement" data-matomo-option="post" title="Sauvegarder" type="submit">
<i aria-hidden="true" class="ri-bookmark-line me-1"></i><span>1</span>
</button>
</form>


</div>
'''
# ---
# name: TestForumViewContent.test_upvotes_counts[upvotes_counts_2]
'''
<div class="d-inline-block" id="upvotesarea10000">


<form hx-post="/upvote/forum/" hx-swap="outerHTML" hx-target="#upvotesarea10000" id="upvote-button10000">
<input name="pk" type="hidden" value="10000"/>
<button class="btn btn-sm btn-ico btn-secondary matomo-event px-2" data-matomo-action="upvote" data-matomo-category="engagement" data-matomo-option="post" title="Sauvegarder" type="submit">
<i aria-hidden="true" class="ri-bookmark-line me-1"></i><span>2</span>
</button>
</form>


</div>
'''
# ---
25 changes: 25 additions & 0 deletions lacommunaute/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,31 @@ def test_filter_subforums_on_tags(self, client, db):
[second_child, third_child]
)

def test_show_subforum_tags(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(
parent=category_forum,
with_public_perms=True,
with_tags=["tag1", "tag2"],
with_image=True,
for_snapshot=True,
name="Test-2",
)
response = client.get(category_forum.get_absolute_url())
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")

def test_numqueries_on_tags(self, client, db, django_assert_num_queries):
category_forum = CategoryForumFactory(with_public_perms=True)
ForumFactory.create_batch(
20, parent=category_forum, with_public_perms=True, with_tags=[f"tag{i}" for i in range(3)]
)
with django_assert_num_queries(18):
client.get(category_forum.get_absolute_url())


@pytest.fixture(name="discussion_area_forum")
def discussion_area_forum_fixture():
Expand Down
7 changes: 5 additions & 2 deletions lacommunaute/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ def get_queryset(self):
return self.filter_queryset(self.get_forum().topics.optimized_for_topics_list(self.request.user.id))

def get_descendants(self):
qs = self.get_forum().get_descendants()

forum_tags = self.request.GET.get("forum_tags")
if forum_tags:
return self.get_forum().get_descendants().filter(tags__slug__in=forum_tags.split(","))
return self.get_forum().get_descendants()
qs = qs.filter(tags__slug__in=forum_tags.split(","))

return qs.prefetch_related("tags")

def get_context_data(self, **kwargs):
forum = self.get_forum()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@
</div>
'''
# ---
# name: TestTopicListView.test_clickable_tags[clickable_tags_page1]
'<a class="tag bg-info-lighter text-info" href="/topics/?tags=tag&amp;page=1">tag</a>'
# ---
# name: TestTopicListView.test_clickable_tags[clickable_tags_page2]
'<a class="tag bg-info-lighter text-info" href="/topics/?tags=tag&amp;page=1">tag</a>'
# ---
# name: test_breadcrumbs_on_topic_view[discussion_area_topic]
'''
<nav aria-label="Fil d'ariane" class="c-breadcrumb">
Expand Down
38 changes: 14 additions & 24 deletions lacommunaute/forum_conversation/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,32 +1015,22 @@ 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}&amp;page=1">'
'<span class="tag bg-info-lighter '
f'text-info">{ tag.name }</span></a>'
),
)
class TestTopicListView:
def test_clickable_tags(self, client, db, snapshot):
forum = ForumFactory(with_public_perms=True)
TopicFactory(with_post=True, forum=forum, with_tags=["tag"])

TopicFactory.create_batch(10, with_post=True, forum=self.forum)
response = self.client.get(self.url + "?page=2")
self.assertContains(
response,
(
f'<a href="{self.url}?tags={tag.slug}&amp;page=1">'
'<span class="tag bg-info-lighter '
f'text-info">{ tag.name }</span></a>'
),
status_code=200,
)
response = client.get(reverse("forum_conversation_extension:topics"))
assert response.status_code == 200
assert str(parse_response_to_soup(response, selector="a.tag")) == snapshot(name="clickable_tags_page1")

# add 10 Topics before the tagged one to put it on the second page
TopicFactory.create_batch(10, with_post=True, forum=forum)

response = client.get(reverse("forum_conversation_extension:topics") + "?page=2")
assert response.status_code == 200
assert str(parse_response_to_soup(response, selector="a.tag")) == snapshot(name="clickable_tags_page2")


class TestPosterTemplate:
Expand Down
Loading

0 comments on commit ed005b7

Please sign in to comment.