Skip to content

Commit

Permalink
refactor(forum/ForumView): gabarit séparé pour les forums de document…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
calummackervoy committed Jun 13, 2024
1 parent 6f8bf3c commit 1f07428
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 70 deletions.
2 changes: 1 addition & 1 deletion lacommunaute/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def test_siblings_in_context(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

self.assertEqual(response.context_data["forums"].count(), 3)
self.assertEqual(response.context_data["sibling_forums"].count(), 3)
for f in forum.get_children():
self.assertContains(response, f.name)

Expand Down
9 changes: 7 additions & 2 deletions lacommunaute/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ class ForumView(BaseForumView, FilteredTopicsListViewMixin):
def get_template_names(self):
if self.request.META.get("HTTP_HX_REQUEST"):
return ["forum_conversation/topic_list.html"]
if self.will_render_documentation_variant():
return ["forum/forum_documentation.html"]
return ["forum/forum_detail.html"]

def will_render_documentation_variant(self):
return self.get_forum().parent and self.forum.is_in_documentation_area

def get_queryset(self):
return self.filter_queryset(self.get_forum().topics.optimized_for_topics_list(self.request.user.id))

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

if forum.parent and forum.is_in_documentation_area:
context["forums"] = forum.get_siblings(include_self=True)
if self.will_render_documentation_variant():
context["sibling_forums"] = forum.get_siblings(include_self=True)
return context


Expand Down
69 changes: 2 additions & 67 deletions lacommunaute/templates/forum/forum_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,80 +30,15 @@ <h1>{{ forum.name }}</h1>
</section>
<section class="s-section">
<div class="s-section__container container">
{% if forums %}
<div class="s-section__row row">
<div class="col-12 col-lg-9">
<div class="row align-items-sm-center mb-3">
<div class="col-12 col-sm">
<span class="badge badge-xs rounded-pill bg-communaute text-white text-decoration-none">
<i class="ri-checkbox-circle-fill"></i>
Certifié par la Plateforme de l'Inclusion le {{ forum.updated|date:"d/m/Y" }}
</span>
</div>
<div class="col-12 col-sm-auto">
{% include "partials/upvotes.html" with obj=forum kind="forum" %}
{% include "partials/social_share_buttons.html" with text=forum.name instance=forum id=forum.pk %}
</div>
{% if forum.image %}
<div class="col-12 col-sm-auto">
<div class="d-none d-md-block forum-image mt-3" loading="lazy">
<img src="{{ forum.image.url }}" alt="{{ forum.name }}" class="rounded img-fluid" />
</div>
</div>
{% endif %}
<div class="col-12 col-sm-auto mt-3">
<div class="textarea_cms_md">{{ forum.description.rendered|urlizetrunc_target_blank:30 }}</div>
</div>
</div>
</div>
<div class="col-12 col-lg-3">
{% if user_can_add_topic %}
<a href="{% url 'forum_conversation:topic_create' forum.slug forum.pk %}"
rel="nofollow"
class="btn btn-primary btn-block btn-ico matomo-event"
data-matomo-category="engagement"
data-matomo-action="contribute"
data-matomo-option="new_topic_on_docs">
<i class="ri-chat-new-line ri-lg"></i>
<span>{% trans "New topic on doc" %}</span>
</a>
<hr>
{% endif %}
<a href="{% url 'forum_extension:forum' forum.parent.slug forum.parent.id %}"
class="matomo-event h3 text-decoration-none d-inline-block"
data-matomo-category="engagement"
data-matomo-action="view"
data-matomo-option="forum">Les autres fiches du thème {{ forum.parent.name }}</a>
<ul class="nav nav-tabs flex-column">
{% for sibling_forum in forums %}
<li class="nav-item">
<a href="{% url 'forum_extension:forum' sibling_forum.slug sibling_forum.id %}" class="nav-link{% if forum.id == sibling_forum.id %} active{% endif %}">{{ sibling_forum.name }}</a>
</li>
{% endfor %}
</ul>
</div>
</div>
<div class="s-section__row row">
<div class="col-12 col-lg-9">
<iframe data-tally-src="https://tally.so/embed/3yyXlx?hideTitle=1&dynamicHeight=1&alignLeft=1"
loading="lazy"
width="100%"
height="100"
frameborder="0"
marginheight="0"
marginwidth="0"
title="Cette fiche vous a-t-elle été utile ?"></iframe>
</div>
</div>
{% else %}
{% block forum_head_content %}
{% if forum.description %}
<div class="s-section__row row">
<div class="col-12">
<div class="textarea_cms_md">{{ forum.description.rendered|urlizetrunc_target_blank:30 }}</div>
</div>
</div>
{% endif %}
{% endif %}
{% endblock forum_head_content %}
</div>
</section>
{% if sub_forums %}
Expand Down
69 changes: 69 additions & 0 deletions lacommunaute/templates/forum/forum_documentation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% extends "forum/forum_detail.html" %}
{% load i18n %}
{% load str_filters %}
{% block forum_head_content %}
<div class="s-section__row row">
<div class="col-12 col-lg-9">
<div class="row align-items-sm-center mb-3">
<div class="col-12 col-sm">
<span class="badge badge-xs rounded-pill bg-communaute text-white text-decoration-none">
<i class="ri-checkbox-circle-fill"></i>
Certifié par la Plateforme de l'Inclusion le {{ forum.updated|date:"d/m/Y" }}
</span>
</div>
<div class="col-12 col-sm-auto">
{% include "partials/upvotes.html" with obj=forum kind="forum" %}
{% include "partials/social_share_buttons.html" with text=forum.name instance=forum id=forum.pk %}
</div>
{% if forum.image %}
<div class="col-12 col-sm-auto">
<div class="d-none d-md-block forum-image mt-3" loading="lazy">
<img src="{{ forum.image.url }}" alt="{{ forum.name }}" class="rounded img-fluid" />
</div>
</div>
{% endif %}
<div class="col-12 col-sm-auto mt-3">
<div class="textarea_cms_md">{{ forum.description.rendered|urlizetrunc_target_blank:30 }}</div>
</div>
</div>
</div>
<div class="col-12 col-lg-3">
{% if user_can_add_topic %}
<a href="{% url 'forum_conversation:topic_create' forum.slug forum.pk %}"
rel="nofollow"
class="btn btn-primary btn-block btn-ico matomo-event"
data-matomo-category="engagement"
data-matomo-action="contribute"
data-matomo-option="new_topic_on_docs">
<i class="ri-chat-new-line ri-lg"></i>
<span>{% trans "New topic on doc" %}</span>
</a>
<hr>
{% endif %}
<a href="{% url 'forum_extension:forum' forum.parent.slug forum.parent.id %}"
class="matomo-event h3 text-decoration-none d-inline-block"
data-matomo-category="engagement"
data-matomo-action="view"
data-matomo-option="forum">Les autres fiches du thème {{ forum.parent.name }}</a>
<ul class="nav nav-tabs flex-column">
{% for sibling_forum in sibling_forums %}
<li class="nav-item">
<a href="{% url 'forum_extension:forum' sibling_forum.slug sibling_forum.id %}" class="nav-link{% if forum.id == sibling_forum.id %} active{% endif %}">{{ sibling_forum.name }}</a>
</li>
{% endfor %}
</ul>
</div>
</div>
<div class="s-section__row row">
<div class="col-12 col-lg-9">
<iframe data-tally-src="https://tally.so/embed/3yyXlx?hideTitle=1&dynamicHeight=1&alignLeft=1"
loading="lazy"
width="100%"
height="100"
frameborder="0"
marginheight="0"
marginwidth="0"
title="Cette fiche vous a-t-elle été utile ?"></iframe>
</div>
</div>
{% endblock forum_head_content %}

0 comments on commit 1f07428

Please sign in to comment.