Skip to content

Commit

Permalink
add linked forums to partner detailview
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Sep 3, 2024
1 parent 98f58da commit 810e2d4
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

</div>
</div>

</div>
</section>

Expand Down Expand Up @@ -112,6 +113,7 @@

</div>
</div>

</div>
</section>

Expand Down Expand Up @@ -171,6 +173,93 @@

</div>
</div>

</div>
</section>


</main>
'''
# ---
# name: test_partner_with_forums[partner_detailview_with_forums]
'''
<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="partner-list" href="/partners/">Nos partenaires</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">
<div class="d-flex gap-3 align-items-center mb-2">

<img alt="Best Partner Ever" class="img-fluid" src="[img src]" width="200"/>

<h1 class="mb-0">Best Partner Ever</h1>
</div>

<h2 class="mt-3">short description for SEO</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"><h3>h3 long MD description</h3>

<p>lorem ipsum dolor sit amet, consectetur adipiscing elit.</p></article>

<div class="mt-3">
<a class="has-external-link" href="https://www.best-partner-ever.com" rel="noopener noreferrer" target="_blank">https://www.best-partner-ever.com</a>
</div>

</div>
</div>

<div class="s-section__row row mt-5">
<div class="col-12">
<h2>Leurs contributions dans la communauté</h2>
</div>
<div class="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 Forum</p>
<div><span class="tag bg-info-lighter text-info">sun</span><span class="tag bg-info-lighter text-info">moon</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-forum-[PK of Forum]/">
<i class="ri-arrow-right-line ri-lg"></i>
</a>
</div>
</div>
</div>

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

</div>
</section>

Expand Down
11 changes: 11 additions & 0 deletions lacommunaute/partner/tests/tests_partner_detailview.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest # noqa

from lacommunaute.forum.factories import ForumFactory
from lacommunaute.partner.factories import PartnerFactory
from lacommunaute.users.factories import UserFactory
from lacommunaute.utils.testing import parse_response_to_soup
Expand All @@ -23,3 +24,13 @@ def test_partner_detailview(client, db, snapshot, user, snapshot_name):
assert str(
parse_response_to_soup(response, selector="main", replace_img_src=True, replace_in_href=[partner])
) == snapshot(name=snapshot_name)


def test_partner_with_forums(client, db, snapshot):
partner = PartnerFactory(for_snapshot=True, with_logo=True)
forum = ForumFactory(with_partner=partner, with_public_perms=True, with_tags=["sun", "moon"], for_snapshot=True)
response = client.get(partner.get_absolute_url())
assert response.status_code == 200
assert str(
parse_response_to_soup(response, selector="main", replace_img_src=True, replace_in_href=[forum])
) == snapshot(name="partner_detailview_with_forums")
15 changes: 15 additions & 0 deletions lacommunaute/partner/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from django.views.generic import DetailView, ListView
from machina.core.loading import get_class

from lacommunaute.forum.models import Forum
from lacommunaute.partner.models import Partner


ForumVisibilityContentTree = get_class("forum.visibility", "ForumVisibilityContentTree")


class PartnerListView(ListView):
model = Partner
template_name = "partner/list.html"
Expand All @@ -14,3 +19,13 @@ class PartnerDetailView(DetailView):
model = Partner
template_name = "partner/detail.html"
context_object_name = "partner"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["sub_forums"] = ForumVisibilityContentTree.from_forums(
self.request.forum_permission_handler.forum_list_filter(
Forum.objects.filter(partner=self.object),
self.request.user,
),
)
return context
8 changes: 8 additions & 0 deletions lacommunaute/templates/partner/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ <h2 class="mt-3">{{ partner.short_description }}</h2>
{% endif %}
</div>
</div>
{% if sub_forums %}
<div class="s-section__row row mt-5">
<div class="col-12">
<h2>Leurs contributions dans la communauté</h2>
</div>
<div class="col-12">{% include "forum/partials/category_subforums_list.html" with sub_forums=sub_forums only %}</div>
</div>
{% endif %}
</div>
</section>
{% endblock content %}

0 comments on commit 810e2d4

Please sign in to comment.