Skip to content

Commit

Permalink
feat(forum_conversation): suppression du triage avant de pouvoir pose…
Browse files Browse the repository at this point in the history
…r une question (#818)

## Description

🎸 les utilisateurs peuvent poser une question dès la page d'accueil,
sans avoir à passer par la page de triage `TopicCreateCheckView`

## Type de changement

🎨 changement d'UI


### Captures d'écran (optionnel)

Écran de triage supprimé

![image](https://github.com/user-attachments/assets/4ec2283e-4e6f-4c6d-9b51-226a80bbbb7e)
  • Loading branch information
vincentporte authored Nov 14, 2024
1 parent 5429fce commit f1b64c6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 166 deletions.
5 changes: 1 addition & 4 deletions lacommunaute/forum_conversation/tests/tests_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ def fixture_public_forum():


def get_create_topic_url(forum):
return (
reverse("forum_conversation:topic_create", kwargs={"forum_pk": forum.pk, "forum_slug": forum.slug})
+ "?checked"
)
return reverse("forum_conversation:topic_create", kwargs={"forum_pk": forum.pk, "forum_slug": forum.slug})


def get_update_topic_url(topic):
Expand Down
74 changes: 6 additions & 68 deletions lacommunaute/forum_conversation/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@ 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,
},
)
+ "?checked=1"
cls.url = reverse(
"forum_conversation:topic_create",
kwargs={
"forum_slug": cls.forum.slug,
"forum_pk": cls.forum.pk,
},
)

cls.post_data = {"subject": faker.text(max_nb_chars=10), "content": faker.paragraph(nb_sentences=5)}
Expand Down Expand Up @@ -230,30 +227,6 @@ def test_checked_tags_are_saved(self, *args):


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")

def test_create_with_new_tags(self, db, client):
forum = ForumFactory(with_public_perms=True)
client.force_login(UserFactory())
Expand Down Expand Up @@ -1049,38 +1022,3 @@ def test_topic_in_its_own_public_forum(self, client, db, snapshot):
response, replace_in_href=[(topic.poster.username, "poster_username")], selector=".poster-infos"
)
assert str(soup) == snapshot(name="topic_in_its_own_public_forum")


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",
)
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: 1 addition & 2 deletions 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 TopicCreateCheckView, TopicListView
from lacommunaute.forum_conversation.views import TopicListView
from lacommunaute.forum_conversation.views_htmx import (
CertifiedPostView,
PostFeedCreateView,
Expand All @@ -18,7 +18,6 @@
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: 0 additions & 19 deletions lacommunaute/forum_conversation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

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 All @@ -31,26 +29,9 @@ 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 "checked" in self.request.GET:
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
73 changes: 0 additions & 73 deletions lacommunaute/templates/forum_conversation/topic_create_check.html

This file was deleted.

0 comments on commit f1b64c6

Please sign in to comment.