Skip to content

Commit

Permalink
feat(forum_conversation): filtrer les questions dans l'espace d'échan…
Browse files Browse the repository at this point in the history
…ges (#681)

## Description

🎸 Rediriger les demandeurs d'emploi et les utilisateurs du site des
emplois vers les services adéquats pour réduire le nombre de questions
'non désirées'

## Type de changement

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

### Points d'attention

🦺 l'accès à la vue `TopicCreateView` est direct lorsque le `forum` a la
propriété `is_in_documentation_area` ou le paramètre `checked=1` dans
l'url.

### Captures d'écran (optionnel)


![image](https://github.com/gip-inclusion/itou-communaute-django/assets/11419273/a751f7ed-cf03-4920-a85e-738e628ab3e5)


![image](https://github.com/gip-inclusion/itou-communaute-django/assets/11419273/d80f6829-3dc6-498c-8aa4-a6a86c1c07e1)
  • Loading branch information
vincentporte authored Jun 24, 2024
1 parent e9d0fa5 commit 48cdd07
Show file tree
Hide file tree
Showing 8 changed files with 429 additions and 36 deletions.
4 changes: 2 additions & 2 deletions lacommunaute/forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def upvotes_count(self):

@cached_property
def is_in_documentation_area(self):
return self.type == Forum.FORUM_CAT or (
self.get_ancestors() and self.get_ancestors().first().type == Forum.FORUM_CAT
return (self.type == Forum.FORUM_CAT and self.get_level() == 0) or (
self.get_level() > 0 and self.get_ancestors().first().type == Forum.FORUM_CAT
)

@cached_property
Expand Down
206 changes: 206 additions & 0 deletions lacommunaute/forum_conversation/tests/__snapshots__/tests_views.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,212 @@
</small>
'''
# ---
# name: TestTopicCreateCheckView.test_get_method[topic_create_check]
'''
<main class="s-main" id="main" role="main">





<section class="s-section" id="main_container">
<div class="s-section__container container">

<div class="row">
<div class="col-12">
<h1>forum</h1>
</div>
</div>
<div class="row c-box">
<div class="col-12 mb-5">
<p class="h2">Quelle est ma situation ?</p>
</div>
<div class="col-12 col-md-6 mb-3">
<div class="card c-card h-100">
<div class="card-header">
<h3 class="h4">Je suis à la recherche d'un emploi</h3>
</div>
<div class="card-body pb-0">
<p>Je recherche des offres d'emploi ou des entreprises près de chez moi</p>
</div>
<div class="card-footer text-center mt-3">
<button class="btn btn-primary" data-bs-target="#rechercheEmploi" data-bs-toggle="modal" type="button">
J'accède aux emplois de l'inclusion
</button>
</div>
</div>
</div>
<div class="col-12 col-md-6 mb-3">
<div class="card c-card h-100">
<div class="card-header">
<h3 class="h4">J'utilise le site des emplois de l'inclusion</h3>
</div>
<div class="card-body pb-0">
<p>
J'ai des questions sur les PASS IAE, leur suspension ou prolongation, le fonctionnement du site des emplois de l'inclusion ou les relations avec l'ASP
</p>
</div>
<div class="card-footer text-center mt-3">
<a class="btn btn-primary" href="https://aide.emplois.inclusion.beta.gouv.fr/hc/fr">
J'accède à la documentation des emplois de l'inclusion
</a>
</div>
</div>
</div>
<div class="col-12 col-md-6 mb-3">
<div class="card c-card h-100">
<div class="card-header">
<h3 class="h4">J'accueille des personnes en PMSMP</h3>
</div>
<div class="card-body pb-0">
<p>
J'ai une question Période de Mise en Situation en Milieu Professionnel, le conventionnement, la déclaration des heures ou le fonctionnement du site Immersion Facilitée
</p>
</div>
<div class="card-footer text-center">
<a class="btn btn-primary" href="https://aide.immersion-facile.beta.gouv.fr/fr/">
J'accède au centre d'aide Immersion Facilitée
</a>
</div>
</div>
</div>
<div class="col-12 col-md-6 mb-3">
<div class="card c-card h-100">
<div class="card-header">
<h3 class="h4">Je suis un/une professionnel/le de l'insertion, en formation ou en activité</h3>
</div>
<div class="card-body pb-0">
<p>
J'ai une question sur l'accompagnement d'une personne éloignée de l'emploi, sur mon parcours de formation ou sur une des fiches pratiques de la communauté
</p>
</div>
<div class="card-footer text-center">
<a class="btn btn-primary" href="/forum/forum-[PK of Forum]/topic/create/?checked=1">Je pose ma question à la communauté</a>
</div>
</div>
</div>
</div>
<div aria-hidden="true" aria-labelledby="rechercheEmploiMiniLabel" class="modal modal--mini fade" id="rechercheEmploi" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="rechercheEmploiLabel">
Vous recherchez un emploi à temps plein, à temps partiel ou en interim ?
</h3>
<button aria-label="Fermer" class="btn-close" data-bs-dismiss="modal" type="button"></button>
</div>
<div class="modal-body home-content-body">
<p class="mb-4">
Ce ne sera pas long !
<br/>
Inscrivez-vous et accédez à toutes les fonctionnalités du site des emplois de l'inclusion.
</p>
<ul class="mb-5">
<li class="d-flex mb-2">
<span>
<i class="text-success ri-checkbox-circle-fill"></i>
</span>
<span class="font-weight-bold ml-2">Créer votre espace candidat</span>
</li>
<li class="d-flex mb-2">
<span>
<i class="text-success ri-checkbox-circle-fill"></i>
</span>
<span class="font-weight-bold ml-2">Rechercher les offres d'emploi à proximité de votre ville</span>
</li>
<li class="d-flex mb-2">
<span>
<i class="text-success ri-checkbox-circle-fill"></i>
</span>
<span class="font-weight-bold ml-2">Candidatez aux offres !</span>
</li>
<li class="d-flex mb-2">
<span>
<i class="text-success ri-checkbox-circle-fill"></i>
</span>
<span class="font-weight-bold ml-2">N'oubliez pas de faire valider votre élégibilité par votre conseiller France Travail.</span>
</li>
</ul>
<p class="text-center">
<a class="btn btn-lg btn-primary" href="https://emplois.inclusion.beta.gouv.fr/signup/job_seeker/situation">Je crée mon espace candidat sur le site des emplois</a>
</p>
</div>
</div>
</div>
</div>

</div>
</section>

</main>
'''
# ---
# name: TestTopicCreateView.test_redirections_on_documentation_forum[topic_create]
'''
<div class="form-group" id="div_id_content">

<label class="control-label" for="id_content">
Message

</label>


<textarea class="form-control" cols="40" id="id_content" name="content" placeholder="Entrez votre message" required="" rows="10"></textarea>





<small class="form-text text-muted">
<a aria-controls="collapseMentionsHelp" aria-expanded="false" data-bs-toggle="collapse" href="#collapseMentionsHelp" role="button">mention d'informations</a>
sur les champs libres
</small>
<div class="collapse" id="collapseMentionsHelp">
<div class="mb-3">
<p>
Nous vous demandons de ne pas nous transmettre d’informations sensibles. Notamment, ne communiquez pas vos opinions philosophiques, syndicales, politiques ou sur votre vie sexuelle. Ces données sont trop personnelles !
</p>
</div>
</div>



</div>
'''
# ---
# name: TestTopicCreateView.test_redirections_on_forum[topic_create]
'''
<div class="form-group" id="div_id_content">

<label class="control-label" for="id_content">
Message

</label>


<textarea class="form-control" cols="40" id="id_content" name="content" placeholder="Entrez votre message" required="" rows="10"></textarea>





<small class="form-text text-muted">
<a aria-controls="collapseMentionsHelp" aria-expanded="false" data-bs-toggle="collapse" href="#collapseMentionsHelp" role="button">mention d'informations</a>
sur les champs libres
</small>
<div class="collapse" id="collapseMentionsHelp">
<div class="mb-3">
<p>
Nous vous demandons de ne pas nous transmettre d’informations sensibles. Notamment, ne communiquez pas vos opinions philosophiques, syndicales, politiques ou sur votre vie sexuelle. Ces données sont trop personnelles !
</p>
</div>
</div>



</div>
'''
# ---
# name: test_breadcrumbs_on_topic_view[discussion_area_topic]
'''
<nav aria-label="Fil d'ariane" class="c-breadcrumb">
Expand Down
76 changes: 70 additions & 6 deletions lacommunaute/forum_conversation/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ class TopicCreateViewTest(TestCase):
def setUpTestData(cls):
cls.poster = UserFactory()
cls.forum = ForumFactory(with_public_perms=True)
cls.url = reverse(
"forum_conversation:topic_create",
kwargs={
"forum_slug": cls.forum.slug,
"forum_pk": cls.forum.pk,
},
cls.url = (
reverse(
"forum_conversation:topic_create",
kwargs={
"forum_slug": cls.forum.slug,
"forum_pk": cls.forum.pk,
},
)
+ "?checked=1"
)

cls.post_data = {"subject": faker.text(max_nb_chars=10), "content": faker.paragraph(nb_sentences=5)}
Expand Down Expand Up @@ -226,6 +229,32 @@ def test_checked_tags_are_saved(self, *args):
self.assertEqual(list(topic.tags.all()), [Tag.objects.first(), Tag.objects.last()])


class TestTopicCreateView:
def test_redirections_on_forum(self, db, client, snapshot):
forum = ForumFactory(with_public_perms=True)
url = reverse("forum_conversation:topic_create", kwargs={"forum_pk": forum.pk, "forum_slug": forum.slug})

response = client.get(url)
assert response.status_code == 302
assert response.url == reverse(
"forum_conversation_extension:topic_create_check", kwargs={"forum_pk": forum.pk, "forum_slug": forum.slug}
)

response = client.get(url + "?checked=1")
assert response.status_code == 200
content = parse_response_to_soup(response, selector="#div_id_content")
assert str(content) == snapshot(name="topic_create")

def test_redirections_on_documentation_forum(self, db, client, snapshot):
forum = CategoryForumFactory(with_child=True, with_public_perms=True).get_children().first()
response = client.get(
reverse("forum_conversation:topic_create", kwargs={"forum_pk": forum.pk, "forum_slug": forum.slug})
)
assert response.status_code == 200
content = parse_response_to_soup(response, selector="#div_id_content")
assert str(content) == snapshot(name="topic_create")


class TopicUpdateViewTest(TestCase):
@classmethod
def setUpTestData(cls):
Expand Down Expand Up @@ -1047,3 +1076,38 @@ def test_context_data(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context_data["forum"], None)
self.assertEqual(response.context_data["loadmoretopic_url"], reverse("forum_conversation_extension:newsfeed"))


class TestTopicCreateCheckView:
def test_get_method(self, client, db, snapshot):
forum = ForumFactory(name="forum")
response = client.get(
reverse(
"forum_conversation_extension:topic_create_check",
kwargs={"forum_slug": forum.slug, "forum_pk": forum.pk},
)
)
assert response.status_code == 200
assertContains(
response,
reverse("forum_conversation:topic_create", kwargs={"forum_slug": forum.slug, "forum_pk": forum.pk})
+ "?checked=1",
)
content = parse_response_to_soup(response, selector="main", replace_in_href=[forum])
assert str(content) == snapshot(name="topic_create_check")

def test_forum_does_not_exist(self, client, db):
response = client.get(
reverse("forum_conversation_extension:topic_create_check", kwargs={"forum_slug": "fake", "forum_pk": 999})
)
assert response.status_code == 404

def test_post_method_not_allowed(self, client, db):
forum = ForumFactory()
response = client.post(
reverse(
"forum_conversation_extension:topic_create_check",
kwargs={"forum_slug": forum.slug, "forum_pk": forum.pk},
)
)
assert response.status_code == 405
3 changes: 2 additions & 1 deletion lacommunaute/forum_conversation/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.urls import include, path

from lacommunaute.forum_conversation.views import NewsFeedTopicListView, TopicListView
from lacommunaute.forum_conversation.views import NewsFeedTopicListView, TopicCreateCheckView, TopicListView
from lacommunaute.forum_conversation.views_htmx import (
CertifiedPostView,
PostFeedCreateView,
Expand All @@ -18,6 +18,7 @@
path("topic/<str:slug>-<int:pk>/showmore/certified", TopicCertifiedPostView.as_view(), name="showmore_certified"),
path("topic/<str:slug>-<int:pk>/comment", PostFeedCreateView.as_view(), name="post_create"),
path("topic/<str:slug>-<int:pk>/certify", CertifiedPostView.as_view(), name="certify"),
path("topic/create/check", TopicCreateCheckView.as_view(), name="topic_create_check"),
]


Expand Down
19 changes: 19 additions & 0 deletions lacommunaute/forum_conversation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from django.conf import settings
from django.contrib import messages
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.views import View
from django.views.generic import ListView
from machina.apps.forum_conversation import views
from machina.core.loading import get_class
Expand Down Expand Up @@ -30,9 +32,26 @@ def form_valid(self, *args, **kwargs):
return valid


class TopicCreateCheckView(View):
def get(self, request, *args, **kwargs):
forum = get_object_or_404(Forum, pk=kwargs["forum_pk"])
return render(request, "forum_conversation/topic_create_check.html", {"forum": forum})


class TopicCreateView(FormValidMixin, views.TopicCreateView):
post_form_class = TopicForm

def get(self, request, *args, **kwargs):
forum = self.get_forum()
if forum.is_in_documentation_area or self.request.GET.get("checked"):
return super().get(request, *args, **kwargs)
return redirect(
reverse(
"forum_conversation_extension:topic_create_check",
kwargs={"forum_pk": forum.pk, "forum_slug": forum.slug},
)
)

def get_success_url(self):
if not self.forum_post.approved:
return reverse(
Expand Down
4 changes: 0 additions & 4 deletions lacommunaute/templates/forum_conversation/topic_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
{% endblock sub_title %}
{% block content %}
<div class="row">
<div class="col-12 mb-3 mb-lg-5">{% include 'partials/banners/emplois_helpdesk.html' %}</div>
<div class="col-12">
<h1>{{ forum.name }}</h1>
</div>
</div>
{% if poll_preview %}
{% include "forum_conversation/forum_polls/poll_preview.html" %}
{% endif %}
<div class="row">
<div class="col-12">
<div class="card post-edit">
Expand Down
Loading

0 comments on commit 48cdd07

Please sign in to comment.