diff --git a/lacommunaute/forum_conversation/tests/tests_views.py b/lacommunaute/forum_conversation/tests/tests_views.py index ce0d7f120..e6562122c 100644 --- a/lacommunaute/forum_conversation/tests/tests_views.py +++ b/lacommunaute/forum_conversation/tests/tests_views.py @@ -12,6 +12,7 @@ from pytest_django.asserts import assertContains from taggit.models import Tag +from lacommunaute.documentation.factories import DocumentFactory from lacommunaute.forum.factories import CategoryForumFactory, ForumFactory from lacommunaute.forum_conversation.enums import Filters from lacommunaute.forum_conversation.factories import ( @@ -1002,53 +1003,22 @@ def test_filter_dropdown_with_tags(self, client, db, public_forum_with_topic, to class TestPosterTemplate: - def test_topic_in_topics_view(self, client, db, topics_url, snapshot): - topic = TopicFactory(with_post=True, poster=UserFactory(first_name="Jeff", last_name="Buckley")) - response = client.get(topics_url) - soup = parse_response_to_soup( - response, replace_in_href=[(topic.poster.username, "poster_username")], selector=".poster-infos" - ) - assert str(soup) == snapshot(name="topic_in_topics_view") - - def test_topic_from_other_public_forum_in_topics_view(self, client, db, topics_url, snapshot): - # first_public_forum - ForumFactory(with_public_perms=True) - - topic = TopicFactory( - with_post=True, - forum=ForumFactory(with_public_perms=True, name="Abby's Forum"), - poster=UserFactory(first_name="Alan", last_name="Turing"), - ) - response = client.get(topics_url) - soup = parse_response_to_soup( - response, - replace_in_href=[ - (topic.poster.username, "poster_username"), - ( - reverse("forum_extension:forum", kwargs={"slug": topic.forum.slug, "pk": topic.forum.pk}), - "forum_url", - ), - ], - selector=".poster-infos", - ) - assert str(soup) == snapshot(name="topic_from_other_public_forum_in_topics_view") - - def test_topic_in_its_own_public_forum(self, client, db, snapshot): - # first_public_forum - ForumFactory(with_public_perms=True) - - topic = TopicFactory( - with_post=True, - forum=ForumFactory(with_public_perms=True, name="Joe's Forum"), - poster=UserFactory(first_name="Dermot", last_name="Turing"), - ) - response = client.get( - reverse("forum_extension:forum", kwargs={"slug": topic.forum.slug, "pk": topic.forum.pk}) - ) - soup = parse_response_to_soup( - response, replace_in_href=[(topic.poster.username, "poster_username")], selector=".poster-infos" - ) - assert str(soup) == snapshot(name="topic_in_its_own_public_forum") + @pytest.mark.parametrize("with_document,snaphot_name", [(True, "with_document"), (False, "without_document")]) + def test_standalone_topic(self, client, db, with_document, snaphot_name, snapshot): + poster = UserFactory(first_name="Jeff", last_name="Buckley") + if with_document: + document = DocumentFactory(for_snapshot=True) + TopicFactory(with_post=True, document=document, poster=poster) + replace_in_href = [ + (poster.username, "poster_username"), + (document.get_absolute_url(), "[Document absolute URL]"), + ] + else: + TopicFactory(with_post=True, poster=poster) + replace_in_href = [(poster.username, "poster_username")] + response = client.get(reverse("forum_conversation_extension:topics")) + soup = parse_response_to_soup(response, replace_in_href=replace_in_href, selector=".poster-infos") + assert str(soup) == snapshot(name=snaphot_name) class TestTopicCreateCheckView: diff --git a/lacommunaute/templates/forum_conversation/partials/poster.html b/lacommunaute/templates/forum_conversation/partials/poster.html index 22aa3ab10..476b3fb67 100644 --- a/lacommunaute/templates/forum_conversation/partials/poster.html +++ b/lacommunaute/templates/forum_conversation/partials/poster.html @@ -17,8 +17,8 @@ {% else %} {{ poster }}, {% endif %} - {% if forum and forum != topic.forum %} - dans {{ topic.forum }}, + {% if topic.document %} + dans {{ topic.document }}, {% endif %} {% endwith %} {% endspaceless %} From 645f5ba167a164bbdca079c34d23f6bff2fd5ca0 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Thu, 10 Oct 2024 16:00:37 +0200 Subject: [PATCH 3/3] wip --- lacommunaute/documentation/views.py | 26 ++++++++++++++++++- lacommunaute/forum_conversation/models.py | 1 + .../documentation/document_detail.html | 12 +++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lacommunaute/documentation/views.py b/lacommunaute/documentation/views.py index ca4ab2504..6af2265d8 100644 --- a/lacommunaute/documentation/views.py +++ b/lacommunaute/documentation/views.py @@ -1,3 +1,4 @@ +from django.conf import settings from django.contrib.auth.mixins import UserPassesTestMixin from django.contrib.contenttypes.models import ContentType from django.db.models import Avg, Count @@ -8,7 +9,12 @@ from django.views.generic.edit import CreateView, UpdateView from taggit.models import Tag +from lacommunaute import documentation from lacommunaute.documentation.models import Category, Document, DocumentRating +from lacommunaute.forum.models import Forum +from lacommunaute.forum_conversation.forms import PostForm +from lacommunaute.forum_conversation.models import Topic +from lacommunaute.forum_conversation.view_mixins import FilteredTopicsListViewMixin class CategoryListView(ListView): @@ -74,11 +80,29 @@ def get_context_data(self, **kwargs): return context -class DocumentDetailView(RatingMixin, DetailView): +class DocumentDetailView(FilteredTopicsListViewMixin, RatingMixin, DetailView): model = Document template_name = "documentation/document_detail.html" context_object_name = "document" + def get_topics(self): + # needs pagination + return self.filter_queryset(Topic.objects.filter(document=self.object).optimized_for_topics_list(self.request.user.id)) + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["topics"] = self.get_topics() + context["form"] = PostForm(user=self.request.user) + + context["loadmoretopic_url"] = self.get_load_more_url(self.object.get_absolute_url()) + context["filter_dropdown_endpoint"] = ( + None if self.request.GET.get("page") else self.object.get_absolute_url()) + + context["loadmoretopic_suffix"] = "topics" + context["forum"] = Forum.objects.get_main_forum() + context = context | self.get_topic_filter_context() + return context + class DocumentRatingView(RatingMixin, View): def post(self, request, *args, **kwargs): diff --git a/lacommunaute/forum_conversation/models.py b/lacommunaute/forum_conversation/models.py index 1fd635dd7..d14f94303 100644 --- a/lacommunaute/forum_conversation/models.py +++ b/lacommunaute/forum_conversation/models.py @@ -38,6 +38,7 @@ def optimized_for_topics_list(self, user_id): "certified_post", "certified_post__post", "certified_post__post__poster", + "document", ) .prefetch_related( "poll", diff --git a/lacommunaute/templates/documentation/document_detail.html b/lacommunaute/templates/documentation/document_detail.html index ec75af4cf..f0e882058 100644 --- a/lacommunaute/templates/documentation/document_detail.html +++ b/lacommunaute/templates/documentation/document_detail.html @@ -38,4 +38,16 @@ +
+
+
+
+
+ {% include "forum_conversation/topic_list.html" with forum=forum %} + +
+
+
+
+
{% endblock content %}