Skip to content

Commit

Permalink
[DSP] add links to related forums
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Feb 21, 2024
1 parent 31c93a5 commit 45d2b6f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@
# Django sites framework
SITE_ID = 1

DSP_FORUM_RELATED_ID = 108

# MATOMO
# ---------------------------------------
MATOMO_BASE_URL = os.getenv("MATOMO_BASE_URL", None)
Expand Down
23 changes: 22 additions & 1 deletion lacommunaute/surveys/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import pytest # noqa
from django.contrib.auth.models import Permission
from django.test import override_settings
from django.urls import reverse
from pytest_django.asserts import assertContains, assertNotContains
from django.contrib.auth.models import Permission

from lacommunaute.forum.factories import CategoryForumFactory
from lacommunaute.surveys.factories import DSPFactory
from lacommunaute.surveys.models import DSP
from lacommunaute.users.factories import UserFactory
Expand Down Expand Up @@ -54,6 +57,14 @@ def test_form_fields(self, db, client):
for field in dsp_choices_list:
assert field in response.context["form"].fields

def test_related_forums(self, db, client):
forum = CategoryForumFactory(with_child=True)
url = reverse("surveys:dsp_create")
with override_settings(DSP_FORUM_RELATED_ID=forum.id):
response = client.get(url)
for related_forum in forum.get_children():
assertContains(response, related_forum.name)

def test_form_valid(self, db, client):
url = reverse("surveys:dsp_create")
client.force_login(UserFactory())
Expand Down Expand Up @@ -86,6 +97,16 @@ def test_user_can_view_own_survey(self, db, client):
response = client.get(url)
assert response.status_code == 200

def test_related_forums(self, db, client):
forum = CategoryForumFactory(with_child=True)
dsp = DSPFactory()
client.force_login(dsp.user)
url = reverse("surveys:dsp_detail", kwargs={"pk": dsp.pk})
with override_settings(DSP_FORUM_RELATED_ID=forum.id):
response = client.get(url)
for related_forum in forum.get_children():
assertContains(response, related_forum.name)


class TestHomeView:
def test_link_to_dsp(self, db, client):
Expand Down
8 changes: 8 additions & 0 deletions lacommunaute/surveys/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from collections import defaultdict

from django.conf import settings
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse_lazy
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView

from lacommunaute.forum.models import Forum
from lacommunaute.surveys.forms import DSPForm
from lacommunaute.surveys.models import DSP

Expand All @@ -21,6 +23,11 @@ def form_valid(self, form):
form.instance.user = self.request.user
return super().form_valid(form)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["related_forums"] = Forum.objects.filter(parent__id=settings.DSP_FORUM_RELATED_ID).order_by("lft")
return context


class DSPDetailView(LoginRequiredMixin, DetailView):
model = DSP
Expand All @@ -42,4 +49,5 @@ def get_context_data(self, **kwargs):
display_method = getattr(self.object, f"get_{field}_display")
dsp_fields[modelfield.verbose_name] = display_method()
context["dsp_fields"] = dsp_fields
context["related_forums"] = Forum.objects.filter(parent__id=settings.DSP_FORUM_RELATED_ID).order_by("lft")
return context
5 changes: 5 additions & 0 deletions lacommunaute/templates/surveys/dsp_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ <h2>Rappel de votre diagnostic</h2>
{% endfor %}
</div>
</div>
<div class="s-section__row row">
<div class="s-section__col col-lg-8 col-12 c-box mb-5">
{% include "surveys/partials/related_forums.html" with related_forums=related_forums only %}
</div>
</div>
<div class="s-section__row row">
<div class="s-section__col col-12 col-lg-8 c-box mb-5">
<iframe data-tally-src="https://tally.so/embed/w8QqMz?alignLeft=1&hideTitle=1&transparentBackground=1&dynamicHeight=1"
Expand Down
7 changes: 7 additions & 0 deletions lacommunaute/templates/surveys/dsp_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ <h1 class="s-title-01__title h1">Diagnostic Parcours IAE</h1>
</div>
</div>
</div>
<div class="s-section__row row">
<div class="s-section__col col-lg-8 col-12">
<div class="c-box mb-5">
{% include "surveys/partials/related_forums.html" with related_forums=related_forums only %}
</div>
</div>
</div>
</div>
</section>
{% endblock content %}
Expand Down
8 changes: 8 additions & 0 deletions lacommunaute/templates/surveys/partials/related_forums.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<strong>Articles associés</strong>
<ul>
{% for forum in related_forums %}
<li>
<a href="{% url 'forum_extension:forum' forum.slug forum.id %}">{{ forum.name }}</a>
</li>
{% endfor %}
</ul>

0 comments on commit 45d2b6f

Please sign in to comment.