diff --git a/lacommunaute/forum/admin.py b/lacommunaute/forum/admin.py index e7b28b8c8..21b624c63 100644 --- a/lacommunaute/forum/admin.py +++ b/lacommunaute/forum/admin.py @@ -7,7 +7,6 @@ class ForumAdmin(BaseForumAdmin): fieldsets = BaseForumAdmin.fieldsets fieldsets[0][1]["fields"] += ("short_description", "certified", "tags", "partner") - fieldsets[1][1]["fields"] += ("kind",) @admin.register(ForumRating) diff --git a/lacommunaute/forum/enums.py b/lacommunaute/forum/enums.py deleted file mode 100644 index 01c37f99f..000000000 --- a/lacommunaute/forum/enums.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.db import models - - -class Kind(models.TextChoices): - PUBLIC_FORUM = "PUBLIC_FORUM", "Espace public" - NEWS = "NEWS", "Actualités" diff --git a/lacommunaute/forum/migrations/0021_remove_forum_kind.py b/lacommunaute/forum/migrations/0021_remove_forum_kind.py new file mode 100644 index 000000000..fd7ff08f2 --- /dev/null +++ b/lacommunaute/forum/migrations/0021_remove_forum_kind.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0.8 on 2024-09-05 14:39 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("forum", "0020_remove_forum_invitation_token_and_more"), + ("search", "0002_remove_kind_in_materialized_view"), + ] + + operations = [ + migrations.RemoveField( + model_name="forum", + name="kind", + ), + ] diff --git a/lacommunaute/forum/models.py b/lacommunaute/forum/models.py index 18486d3cc..0f73b9baa 100644 --- a/lacommunaute/forum/models.py +++ b/lacommunaute/forum/models.py @@ -8,7 +8,6 @@ from storages.backends.s3boto3 import S3Boto3Storage from taggit.managers import TaggableManager -from lacommunaute.forum.enums import Kind as Forum_Kind from lacommunaute.forum_conversation.models import Topic from lacommunaute.forum_upvote.models import UpVote from lacommunaute.partner.models import Partner @@ -16,14 +15,11 @@ class ForumQuerySet(models.QuerySet): - def public(self): - return self.filter(kind=Forum_Kind.PUBLIC_FORUM) + def get_main_forum(self): + return self.filter(lft=1, level=0).first() class Forum(AbstractForum): - kind = models.CharField( - max_length=20, choices=Forum_Kind.choices, default=Forum_Kind.PUBLIC_FORUM, verbose_name="Type" - ) short_description = models.CharField( max_length=400, blank=True, null=True, verbose_name="Description courte (SEO)" ) @@ -67,11 +63,7 @@ def is_in_documentation_area(self): @cached_property def is_toplevel_discussion_area(self): - return self == Forum.objects.filter(kind=Forum_Kind.PUBLIC_FORUM, lft=1, level=0).first() - - @cached_property - def is_newsfeed(self): - return self.kind == Forum_Kind.NEWS + return self == Forum.objects.get_main_forum() def get_session_rating(self, session_key): return getattr(ForumRating.objects.filter(forum=self, session_id=session_key).first(), "rating", None) diff --git a/lacommunaute/forum/tests/__snapshots__/tests_views.ambr b/lacommunaute/forum/tests/__snapshots__/tests_views.ambr index 563343cd8..99e56d8d1 100644 --- a/lacommunaute/forum/tests/__snapshots__/tests_views.ambr +++ b/lacommunaute/forum/tests/__snapshots__/tests_views.ambr @@ -77,22 +77,6 @@ - - - ''' -# --- -# name: TestBreadcrumb.test_newsfeed_forum[newsfeed_forum] - ''' - ''' diff --git a/lacommunaute/forum/tests/test_categoryforum_createview.py b/lacommunaute/forum/tests/test_categoryforum_createview.py index a2f21ee93..05008883f 100644 --- a/lacommunaute/forum/tests/test_categoryforum_createview.py +++ b/lacommunaute/forum/tests/test_categoryforum_createview.py @@ -3,7 +3,6 @@ from machina.core.db.models import get_model from pytest_django.asserts import assertContains -from lacommunaute.forum.enums import Kind as ForumKind from lacommunaute.forum.models import Forum from lacommunaute.users.factories import UserFactory @@ -56,7 +55,6 @@ def test_create_category_with_perms(client, db): forum = Forum.objects.get() assert forum.type == Forum.FORUM_CAT - assert forum.kind == ForumKind.PUBLIC_FORUM assert forum.parent is None assert UserForumPermission.objects.filter(forum=forum).count() == 14 diff --git a/lacommunaute/forum/tests/test_subcategoryforum_createview.py b/lacommunaute/forum/tests/test_subcategoryforum_createview.py index 714d91f4c..cbf9d60a5 100644 --- a/lacommunaute/forum/tests/test_subcategoryforum_createview.py +++ b/lacommunaute/forum/tests/test_subcategoryforum_createview.py @@ -3,7 +3,6 @@ from machina.core.db.models import get_model from pytest_django.asserts import assertContains -from lacommunaute.forum.enums import Kind as ForumKind from lacommunaute.forum.models import Forum from lacommunaute.users.factories import UserFactory from lacommunaute.forum.factories import CategoryForumFactory @@ -65,7 +64,6 @@ def test_create_subcategory_with_perms(client, db): forum = category_forum.children.get() assert forum.type == Forum.FORUM_POST - assert forum.kind == ForumKind.PUBLIC_FORUM assert forum.parent == category_forum assert UserForumPermission.objects.filter(forum=forum).count() == 14 diff --git a/lacommunaute/forum/tests/tests_model.py b/lacommunaute/forum/tests/tests_model.py index d8848085d..dcd0a13ab 100644 --- a/lacommunaute/forum/tests/tests_model.py +++ b/lacommunaute/forum/tests/tests_model.py @@ -1,20 +1,12 @@ from django.conf import settings from django.test import TestCase -from lacommunaute.forum.enums import Kind as ForumKind from lacommunaute.forum.factories import CategoryForumFactory, ForumFactory, ForumRatingFactory from lacommunaute.forum.models import Forum from lacommunaute.forum_conversation.factories import TopicFactory from lacommunaute.users.factories import UserFactory -class ForumManagerTest(TestCase): - def test_public_method(self): - forum = ForumFactory(kind=ForumKind.PUBLIC_FORUM) - ForumFactory(kind=ForumKind.NEWS) - self.assertEqual(forum, Forum.objects.public().get()) - - class ForumModelTest(TestCase): def test_get_unanswered_topics(self): topic1 = TopicFactory(forum=ForumFactory(), posts_count=1) @@ -31,12 +23,6 @@ def test_count_unanswered_topics(self): TopicFactory(forum=ForumFactory(parent=topic.forum), posts_count=1) self.assertEqual(topic.forum.count_unanswered_topics, 2) - def test_kind(self): - self.assertEqual( - Forum.kind.field.flatchoices, - [("PUBLIC_FORUM", "Espace public"), ("NEWS", "Actualités")], - ) - def test_get_absolute_url(self): forum = ForumFactory() self.assertEqual( @@ -80,20 +66,11 @@ def test_is_toplevel_discussion_area(self): sub_discussion_area_forum = ForumFactory(parent=discussion_area_forum) forum = ForumFactory() sub_forum = ForumFactory(parent=forum) - news_forum = ForumFactory(kind=ForumKind.NEWS) self.assertTrue(discussion_area_forum.is_toplevel_discussion_area) self.assertFalse(sub_discussion_area_forum.is_toplevel_discussion_area) self.assertFalse(forum.is_toplevel_discussion_area) self.assertFalse(sub_forum.is_toplevel_discussion_area) - self.assertFalse(news_forum.is_toplevel_discussion_area) - - def test_is_newsfeed(self): - news_forum = ForumFactory(kind=ForumKind.NEWS) - discussion_area_forum = ForumFactory() - - self.assertTrue(news_forum.is_newsfeed) - self.assertFalse(discussion_area_forum.is_newsfeed) def test_get_session_rating(self): forum = ForumFactory() @@ -111,3 +88,15 @@ def test_get_average_rating(self): ForumRatingFactory(forum=forum, rating=5) self.assertEqual(forum.get_average_rating(), 3) + + +class TestForumQueryset: + def test_get_main_forum_wo_forum(self, db): + assert Forum.objects.get_main_forum() is None + + def test_get_main_forum_w_several_forums(self, db): + # level 0 + forums = ForumFactory.create_batch(2) + # level 1 + ForumFactory(parent=forums[0]) + assert Forum.objects.get_main_forum() == forums[0] diff --git a/lacommunaute/forum/tests/tests_views.py b/lacommunaute/forum/tests/tests_views.py index a49e2af5e..3ae9a6fdc 100644 --- a/lacommunaute/forum/tests/tests_views.py +++ b/lacommunaute/forum/tests/tests_views.py @@ -748,10 +748,3 @@ def test_grandchild_category_forum(self, client, db, snapshot, discussion_area_f replace_in_href=[parent_forum, parent_forum.get_children().first()], ) assert str(content) == snapshot(name="grandchild_category_forum") - - def test_newsfeed_forum(self, client, db, snapshot, discussion_area_forum): - forum = ForumFactory(kind="NEWS", with_public_perms=True) - response = client.get(reverse("forum_extension:forum", kwargs={"pk": forum.pk, "slug": forum.slug})) - assert response.status_code == 200 - content = parse_response_to_soup(response, selector="nav.c-breadcrumb") - assert str(content) == snapshot(name="newsfeed_forum") diff --git a/lacommunaute/forum/views.py b/lacommunaute/forum/views.py index c0914a8a3..f16088f96 100644 --- a/lacommunaute/forum/views.py +++ b/lacommunaute/forum/views.py @@ -12,7 +12,6 @@ from machina.core.loading import get_class from taggit.models import Tag -from lacommunaute.forum.enums import Kind as ForumKind from lacommunaute.forum.forms import ForumForm from lacommunaute.forum.models import Forum, ForumRating from lacommunaute.forum_conversation.forms import PostForm @@ -140,7 +139,7 @@ class CategoryForumListView(ListView): context_object_name = "forums" def get_queryset(self) -> QuerySet[Forum]: - return Forum.objects.filter(type=Forum.FORUM_CAT, kind=ForumKind.PUBLIC_FORUM, level=0) + return Forum.objects.filter(type=Forum.FORUM_CAT, level=0) class BaseCategoryForumCreateView(UserPassesTestMixin, CreateView): @@ -151,7 +150,6 @@ def test_func(self): return self.request.user.is_superuser def form_valid(self, form): - form.instance.kind = ForumKind.PUBLIC_FORUM response = super().form_valid(form) add_public_perms_on_forum(form.instance) return response diff --git a/lacommunaute/forum_conversation/shortcuts.py b/lacommunaute/forum_conversation/shortcuts.py index 6aad82274..c85bf9e55 100644 --- a/lacommunaute/forum_conversation/shortcuts.py +++ b/lacommunaute/forum_conversation/shortcuts.py @@ -1,7 +1,6 @@ from django.contrib.contenttypes.models import ContentType from django.db.models import Count, Exists, OuterRef, Prefetch, Q, QuerySet -from lacommunaute.forum.enums import Kind as Forum_Kind from lacommunaute.forum_conversation.models import Post, Topic from lacommunaute.forum_upvote.models import UpVote from lacommunaute.users.models import User @@ -37,5 +36,5 @@ def get_posts_of_a_topic_except_first_one(topic: Topic, user: User) -> QuerySet[ return qs.order_by("created") -def can_certify_post(forum, user): - return user.is_authenticated and forum.kind == Forum_Kind.PUBLIC_FORUM and user.is_staff +def can_certify_post(user): + return user.is_authenticated and user.is_staff diff --git a/lacommunaute/forum_conversation/tests/__snapshots__/tests_views.ambr b/lacommunaute/forum_conversation/tests/__snapshots__/tests_views.ambr index cf9fef414..60c3ba87f 100644 --- a/lacommunaute/forum_conversation/tests/__snapshots__/tests_views.ambr +++ b/lacommunaute/forum_conversation/tests/__snapshots__/tests_views.ambr @@ -320,22 +320,6 @@ ''' # --- -# name: test_breadcrumbs_on_topic_view[newsfeed_topic] - ''' - - ''' -# --- # name: test_queryset_for_tagged_topic[tagged_topic] '''
- - {{ topic.subject }} - {% if topic.is_locked %} - - {% endif %} - -
-