From fedd5cac8e46aee5cea9644e783380ad90b04ad3 Mon Sep 17 00:00:00 2001 From: Calum Mackervoy Date: Wed, 3 Jul 2024 17:32:20 +0200 Subject: [PATCH] =?UTF-8?q?refactor(forum):=20gabarit=20s=C3=A9par=C3=A9?= =?UTF-8?q?=20pour=20les=20forums=20de=20documentation=20(#680)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description 🎸 Séparation des gabarits servis selon la type de forum, en partageant le même parent ## Type de changement 🎢 Nouvelle fonctionnalité (changement non cassant qui ajoute une fonctionnalité). --- lacommunaute/forum/factories.py | 3 + .../tests/__snapshots__/tests_views.ambr | 121 +++++++++- lacommunaute/forum/tests/tests_views.py | 159 ++++++++++++- lacommunaute/forum/views.py | 14 +- .../templates/forum/forum_detail.html | 210 +++++++----------- .../templates/forum/forum_documentation.html | 66 ++++++ .../forum/forum_documentation_category.html | 42 ++++ lacommunaute/templates/forum/forum_list.html | 105 --------- lacommunaute/templates/forum/index.html | 45 +++- lacommunaute/utils/testing.py | 26 ++- 10 files changed, 551 insertions(+), 240 deletions(-) create mode 100644 lacommunaute/templates/forum/forum_documentation.html create mode 100644 lacommunaute/templates/forum/forum_documentation_category.html delete mode 100644 lacommunaute/templates/forum/forum_list.html diff --git a/lacommunaute/forum/factories.py b/lacommunaute/forum/factories.py index a0705584d..0f94434da 100644 --- a/lacommunaute/forum/factories.py +++ b/lacommunaute/forum/factories.py @@ -19,6 +19,9 @@ class Meta: class Params: with_image = factory.Trait(image=factory.django.ImageField(filename="banner.jpg")) + for_snapshot = factory.Trait( + name="Test Forum", description="Test description", short_description="Test description" + ) @factory.post_generation def with_public_perms(self, create, extracted, **kwargs): diff --git a/lacommunaute/forum/tests/__snapshots__/tests_views.ambr b/lacommunaute/forum/tests/__snapshots__/tests_views.ambr index f97681d40..915c2577b 100644 --- a/lacommunaute/forum/tests/__snapshots__/tests_views.ambr +++ b/lacommunaute/forum/tests/__snapshots__/tests_views.ambr @@ -137,7 +137,124 @@ ''' # --- -# name: TestForumView.test_not_rated_forum[not_rated_forum] +# name: TestDocumentationCategoryForumContent.test_documentation_category_foot_content[documentation_category_add_file_control] + ''' +
+ +
+ ''' +# --- +# name: TestDocumentationCategoryForumContent.test_documentation_category_subforum_list[documentation_category_subforum_list] + ''' +
+ +
+ +
+ +
+ ''' +# --- +# name: TestDocumentationForumContent.test_documentation_forum_header_content[template_documentation_link_to_parent] + 'Les autres fiches du thème Parent-Forum' +# --- +# name: TestDocumentationForumContent.test_documentation_forum_share_actions[template_documentation_social_share] + ''' + + ''' +# --- +# name: TestDocumentationForumContent.test_documentation_forum_share_actions[template_documentation_upvotes] + ''' +
+ + + + 0 + + + +
+ ''' +# --- +# name: TestForumDetailContent.test_forum_detail_foot_content[forum_detail_forum_actions_block] + ''' +
+ + + + + + Poser une question + + + + + +
+ ''' +# --- +# name: TestForumDetailContent.test_forum_detail_header_content[forum_detail_heading] + ''' +
+
+
+
+

Test Forum

+ +

Test description

+
+
+
+
+ ''' +# --- +# name: TestForumDetailContent.test_forum_detail_subforum_content_rendered[forum_detail_subforums] + ''' + + ''' +# --- +# name: TestForumViewContent.test_not_rated_forum[not_rated_forum] '''

@@ -172,7 +289,7 @@
''' # --- -# name: TestForumView.test_rated_forum[rated_forum] +# name: TestForumViewContent.test_rated_forum[rated_forum] '''

diff --git a/lacommunaute/forum/tests/tests_views.py b/lacommunaute/forum/tests/tests_views.py index 36c731512..fade8e5a5 100644 --- a/lacommunaute/forum/tests/tests_views.py +++ b/lacommunaute/forum/tests/tests_views.py @@ -1,4 +1,5 @@ import pytest # noqa +import re from django.contrib.contenttypes.models import ContentType from django.template.defaultfilters import truncatechars_html from django.test import RequestFactory, TestCase @@ -9,13 +10,14 @@ 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.views import ForumView from lacommunaute.forum_conversation.enums import Filters from lacommunaute.forum_conversation.factories import CertifiedPostFactory, PostFactory, TopicFactory from lacommunaute.forum_conversation.forms import PostForm from lacommunaute.forum_conversation.models import Topic from lacommunaute.users.factories import UserFactory -from lacommunaute.utils.testing import parse_response_to_soup +from lacommunaute.utils.testing import parse_response_to_soup, reset_model_sequence_fixture faker = Faker() @@ -107,6 +109,15 @@ def test_template_name(self): response = self.client.get(self.url, **{"HTTP_HX_REQUEST": "true"}) self.assertTemplateUsed(response, "forum_conversation/topic_list.html") + documentation_category_forum = CategoryForumFactory(with_public_perms=True, with_child=True) + documentation_forum = documentation_category_forum.children.first() + + response = self.client.get(documentation_category_forum.get_absolute_url()) + self.assertTemplateUsed(response, "forum/forum_documentation_category.html") + + response = self.client.get(documentation_forum.get_absolute_url()) + self.assertTemplateUsed(response, "forum/forum_documentation.html") + def test_show_comments(self): topic_url = reverse( "forum_conversation_extension:showmore_posts", @@ -334,7 +345,7 @@ def test_siblings_in_context(self): response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertEqual(response.context_data["forums"].count(), 3) + self.assertEqual(response.context_data["sibling_forums"].count(), 3) for f in forum.get_children(): self.assertContains(response, f.name) @@ -513,7 +524,7 @@ def test_banner_display_on_subcategory_forum(self): self.assertContains(response, forum.image.url.split("=")[0]) -class TestForumView: +class TestForumViewContent: def test_not_rated_forum(self, client, db, snapshot): category_forum = CategoryForumFactory(with_public_perms=True, with_child=True, name="B Category") forum = category_forum.get_children().first() @@ -535,6 +546,148 @@ def test_rated_forum(self, client, db, snapshot): assert str(content) == snapshot(name="rated_forum") +reset_forum_sequence = pytest.fixture(reset_model_sequence_fixture(Forum)) + + +@pytest.fixture(name="forum_for_snapshot") +def forum_for_snapshot_fixture(): + return ForumFactory( + parent=ForumFactory(with_public_perms=True, name="Parent-Forum"), + with_public_perms=True, + with_image=True, + for_snapshot=True, + ) + + +@pytest.fixture(name="documentation_forum") +def documentation_forum_fixture(): + return ForumFactory( + parent=CategoryForumFactory(with_public_perms=True, name="Parent-Forum"), + with_public_perms=True, + with_image=True, + for_snapshot=True, + ) + + +class TestForumDetailContent: + def test_template_forum_detail_share_actions(self, client, db, snapshot): + forum = ForumFactory(with_public_perms=True) + response = client.get(forum.get_absolute_url()) + content = parse_response_to_soup(response, replace_in_href=[forum]) + + assert len(content.select(f"#upvotesarea{str(forum.pk)}")) == 0 + assert len(content.select(f"#dropdownMenuSocialShare{str(forum.pk)}")) == 0 + + def test_forum_detail_header_content(self, client, db, snapshot, reset_forum_sequence, forum_for_snapshot): + response = client.get(forum_for_snapshot.get_absolute_url()) + content = parse_response_to_soup(response) + + assert str(content.select("section.s-title-01")[0]) == snapshot(name="forum_detail_heading") + assert ( + len( + content.select( + "div.textarea_cms_md", string=(lambda x: x.startswith(str(forum_for_snapshot.description)[:10])) + ) + ) + == 1 + ) + + # NOTE: tests no subforum content rendered + assert len(content.select("ul.list-group")) == 0 + + def test_forum_detail_subforum_content_rendered( + self, client, db, snapshot, reset_forum_sequence, forum_for_snapshot + ): + # subforum + ForumFactory(parent=forum_for_snapshot, with_public_perms=True, name="Test-Child", for_snapshot=True) + + response = client.get(forum_for_snapshot.get_absolute_url()) + content = parse_response_to_soup(response) + + subforum_content = content.select("ul.list-group") + assert len(subforum_content) == 1 + assert str(subforum_content[0]) == snapshot(name="forum_detail_subforums") + + def test_forum_detail_foot_content(self, client, db, snapshot, reset_forum_sequence, forum_for_snapshot): + response = client.get(forum_for_snapshot.get_absolute_url()) + content = parse_response_to_soup(response) + + assert forum_for_snapshot.is_forum + forum_actions_block = content.select("div.forum-actions-block") + assert len(forum_actions_block) == 1 + assert str(forum_actions_block[0]) == snapshot(name="forum_detail_forum_actions_block") + + +class TestDocumentationForumContent: + def test_documentation_forum_share_actions(self, client, db, snapshot, reset_forum_sequence, documentation_forum): + response = client.get(documentation_forum.get_absolute_url()) + content = parse_response_to_soup(response) + + upvotes_area = content.select(f"#upvotesarea{str(documentation_forum.pk)}")[0] + assert str(upvotes_area) == snapshot(name="template_documentation_upvotes") + social_share_area = content.select(f"#dropdownMenuSocialShare{str(documentation_forum.pk)}")[0] + assert str(social_share_area) == snapshot(name="template_documentation_social_share") + + def test_documentation_forum_header_content(self, client, db, snapshot, reset_forum_sequence, documentation_forum): + sibling_forum = ForumFactory(parent=documentation_forum.parent, with_public_perms=True, name="Test-2") + + response = client.get(documentation_forum.get_absolute_url()) + content = parse_response_to_soup(response) + + assert len(content.find_all("img", src=re.compile(documentation_forum.image.name))) == 1 + assert ( + len( + content.select( + "div.textarea_cms_md", string=(lambda x: x.startswith(str(documentation_forum.description)[:10])) + ) + ) + == 1 + ) + + user_add_topic = content.find_all( + "a", + href=str( + reverse("forum_conversation:topic_create", args=(documentation_forum.slug, documentation_forum.pk)) + ), + ) + assert len(user_add_topic) == 2 + + link_to_parent = content.find_all("a", href=documentation_forum.parent.get_absolute_url()) + assert len(link_to_parent) == 1 + assert (str(link_to_parent[0])) == snapshot(name="template_documentation_link_to_parent") + + assert len(content.find_all("a", href=sibling_forum.get_absolute_url())) == 1 + + +class TestDocumentationCategoryForumContent: + def test_documentation_category_subforum_list( + self, client, db, snapshot, reset_forum_sequence, documentation_forum + ): + response = client.get(documentation_forum.parent.get_absolute_url()) + content = parse_response_to_soup(response, replace_img_src=True) + + subforum_content = content.select("#documentation-category-subforums") + assert len(subforum_content) == 1 + assert str(subforum_content[0]) == snapshot(name="documentation_category_subforum_list") + + def test_documentation_category_foot_content( + self, client, db, snapshot, reset_forum_sequence, documentation_forum + ): + response = client.get(documentation_forum.parent.get_absolute_url()) + content = parse_response_to_soup(response) + + # require superuser permission + assert len(content.select("#add-documentation-to-category-control")) == 0 + + client.force_login(UserFactory(is_superuser=True)) + response = client.get(documentation_forum.parent.get_absolute_url()) + content = parse_response_to_soup(response) + + add_documentation_control = content.select("#add-documentation-to-category-control") + assert len(add_documentation_control) == 1 + assert str(add_documentation_control[0]) == snapshot(name="documentation_category_add_file_control") + + @pytest.fixture(name="discussion_area_forum") def discussion_area_forum_fixture(): return ForumFactory(with_public_perms=True, name="A Forum") diff --git a/lacommunaute/forum/views.py b/lacommunaute/forum/views.py index f1980023f..766c5ef55 100644 --- a/lacommunaute/forum/views.py +++ b/lacommunaute/forum/views.py @@ -31,8 +31,18 @@ class ForumView(BaseForumView, FilteredTopicsListViewMixin): def get_template_names(self): if self.request.META.get("HTTP_HX_REQUEST"): return ["forum_conversation/topic_list.html"] + if self.will_render_documentation_variant(): + return ["forum/forum_documentation.html"] + if self.will_render_documentation_category_variant(): + return ["forum/forum_documentation_category.html"] return ["forum/forum_detail.html"] + def will_render_documentation_variant(self): + return self.get_forum().parent and self.forum.is_in_documentation_area + + def will_render_documentation_category_variant(self): + return self.get_forum().is_in_documentation_area and self.forum.level == 0 + def get_queryset(self): return self.filter_queryset(self.get_forum().topics.optimized_for_topics_list(self.request.user.id)) @@ -65,8 +75,8 @@ def get_context_data(self, **kwargs): ) context = context | self.get_topic_filter_context() - if forum.parent and forum.is_in_documentation_area: - context["forums"] = forum.get_siblings(include_self=True) + if self.will_render_documentation_variant(): + context["sibling_forums"] = forum.get_siblings(include_self=True) return context diff --git a/lacommunaute/templates/forum/forum_detail.html b/lacommunaute/templates/forum/forum_detail.html index de942b5ba..b682646ba 100644 --- a/lacommunaute/templates/forum/forum_detail.html +++ b/lacommunaute/templates/forum/forum_detail.html @@ -30,69 +30,7 @@

{{ forum.name }}

- {% if forums %} -
-
-
-
- - - Certifié par la Plateforme de l'Inclusion le {{ forum.updated|date:"d/m/Y" }} - -
-
- {% include "partials/upvotes.html" with obj=forum kind="forum" %} - {% include "partials/social_share_buttons.html" with text=forum.name instance=forum id=forum.pk %} -
- {% if forum.image %} -
-
- {{ forum.name }} -
-
- {% endif %} -
-
{{ forum.description.rendered|urlizetrunc_target_blank:30 }}
-
-
- {% comment %} Proposition A Testing {% endcomment %} - {% include "forum/partials/rating.html" with forum=forum rating_area_id="1" %} - {% comment %} Proposition A Testing {% endcomment %} -
-
- {% if user_can_add_topic %} - - - {% trans "New topic on doc" %} - - {% endif %} - {% comment %} Proposition B Testing {% endcomment %} - {% include "forum/partials/rating.html" with forum=forum onSidebar=True rating_area_id="2" hidden=True %} - {% comment %} Proposition B Testing {% endcomment %} -
- Les autres fiches du thème {{ forum.parent.name }} - - {% comment %} Proposition C Testing {% endcomment %} - {% include "forum/partials/rating.html" with forum=forum onSidebar=True rating_area_id="3" hidden=True %} - {% comment %} Proposition C Testing {% endcomment %} -
-
- {% else %} + {% block forum_head_content %} {% if forum.description %}
@@ -100,83 +38,103 @@

{{ forum.name }}

{% endif %} - {% endif %} + {% endblock forum_head_content %}
{% if sub_forums %}
-
{% forum_list sub_forums %}
+
+ {% block subforum_list %} +
    + {% for node in sub_forums.top_nodes %} +
  • +
    + {{ node.obj.name }} + + {% if node.obj.kind == 'PRIVATE_FORUM' %} + {{ node.obj.members_group.user_set.count }} membres - + {% endif %} + {% if node.topics_count > 1 %} + {{ node.topics_count }} {% trans "Topics" %} + {% else %} + {{ node.topics_count }} {% trans "Topic" %} + {% endif %} + - + {% if node.posts_count > 1 %} + {{ node.posts_count }} {% trans "Posts" %} + {% else %} + {{ node.posts_count }} {% trans "Post" %} + {% endif %} + +
    +
  • + {% endfor %} +
+ {% endblock subforum_list %} +
{% endif %} - {% if forum.is_forum %} -
-
-
- {% comment %}{% get_permission 'can_add_topic' forum request.user as user_can_add_topic %}{% endcomment %} - {% get_permission 'can_approve_posts' forum request.user as user_can_access_stats %} - {% if user_can_add_topic or user_can_access_stats %} -
- {% if user_can_add_topic %} - - - - {% if forums %} - {% trans "New topic on doc" %} - {% elif forum.kind == 'NEWS' %} - {% trans "New news" %} - {% else %} - {% trans "New topic" %} - {% endif %} - - - {% endif %} - {% if user_can_access_stats and forum.members_group %} - - - {% endif %} -
- {% endif %} -
-
-
-
-
-
-
-
- {% with unread_topics=unread_topics %} - {% include "forum_conversation/topic_list.html" %} - - {% endwith %} -
+ {% block forum_foot_content %} + {% if forum.is_forum %} +
+
+
+ {% comment %}{% get_permission 'can_add_topic' forum request.user as user_can_add_topic %}{% endcomment %} + {% get_permission 'can_approve_posts' forum request.user as user_can_access_stats %} + {% if user_can_add_topic or user_can_access_stats %} +
+ {% if user_can_add_topic %} + + + + {% if forums %} + {% trans "New topic on doc" %} + {% elif forum.kind == 'NEWS' %} + {% trans "New news" %} + {% else %} + {% trans "New topic" %} + {% endif %} + + + {% endif %} + {% if user_can_access_stats and forum.members_group %} + + + {% endif %} +
+ {% endif %}
-
-
- {% elif forum.is_category and user.is_superuser %} -
-
+
+
+
+
+
+ {% with unread_topics=unread_topics %} + {% include "forum_conversation/topic_list.html" %} + + {% endwith %} +
+
-
- - {% endif %} + + {% endif %} + {% endblock forum_foot_content %} {% endblock content %} {% block extra_js %} {{ block.super }} diff --git a/lacommunaute/templates/forum/forum_documentation.html b/lacommunaute/templates/forum/forum_documentation.html new file mode 100644 index 000000000..efca105dc --- /dev/null +++ b/lacommunaute/templates/forum/forum_documentation.html @@ -0,0 +1,66 @@ +{% extends "forum/forum_detail.html" %} +{% load i18n %} +{% load str_filters %} +{% block forum_head_content %} +
+
+
+
+ + + Certifié par la Plateforme de l'Inclusion le {{ forum.updated|date:"d/m/Y" }} + +
+
+ {% include "partials/upvotes.html" with obj=forum kind="forum" %} + {% include "partials/social_share_buttons.html" with text=forum.name instance=forum id=forum.pk %} +
+ {% if forum.image %} +
+
+ {{ forum.name }} +
+
+ {% endif %} +
+
{{ forum.description.rendered|urlizetrunc_target_blank:30 }}
+
+ {% comment %} Proposition A Testing {% endcomment %} + {% include "forum/partials/rating.html" with forum=forum rating_area_id="1" %} + {% comment %} Proposition A Testing {% endcomment %} +
+
+
+ {% if user_can_add_topic %} + + + {% trans "New topic on doc" %} + + {% endif %} + {% comment %} Proposition B Testing {% endcomment %} + {% include "forum/partials/rating.html" with forum=forum onSidebar=True rating_area_id="2" hidden=True %} + {% comment %} Proposition B Testing {% endcomment %} +
+ Les autres fiches du thème {{ forum.parent.name }} + + {% comment %} Proposition C Testing {% endcomment %} + {% include "forum/partials/rating.html" with forum=forum onSidebar=True rating_area_id="3" hidden=True %} + {% comment %} Proposition C Testing {% endcomment %} +
+
+{% endblock forum_head_content %} diff --git a/lacommunaute/templates/forum/forum_documentation_category.html b/lacommunaute/templates/forum/forum_documentation_category.html new file mode 100644 index 000000000..5d41af56d --- /dev/null +++ b/lacommunaute/templates/forum/forum_documentation_category.html @@ -0,0 +1,42 @@ +{% extends "forum/forum_detail.html" %} +{% block subforum_list %} +
+ {% for node in sub_forums.top_nodes %} +
+ +
+ {% endfor %} +
+{% endblock subforum_list %} +{% block forum_foot_content %} + {% if user.is_superuser %} +
+ +
+ {% endif %} +{% endblock %} diff --git a/lacommunaute/templates/forum/forum_list.html b/lacommunaute/templates/forum/forum_list.html deleted file mode 100644 index dddcfb793..000000000 --- a/lacommunaute/templates/forum/forum_list.html +++ /dev/null @@ -1,105 +0,0 @@ -{% load i18n %} -{% load mptt_tags %} -{% load forum_conversation_tags %} -{% load forum_member_tags %} -{% load forum_tracking_tags %} -{% load str_filters %} -{% load date_filters %} -{% if forum_contents.nodes %} - {% if root_level == 0 %} - {% for node in forum_contents.top_nodes %} -
-
- {% if node.obj.image %} -
- {{ node.obj.name }} -
- {% endif %} -
-

- {{ node.obj.name }} -

-

{% include "forum/partials/topics_and_members_counts.html" %}

-
-
-
- {% if node.obj.description.rendered %}{{ node.obj.description.rendered|urlizetrunc_target_blank:30 }}{% endif %} - {% if node.children %} - -
-
    - {% for child in node.children %} -
  • -
    - {{ child.obj.name }} - {% include "forum/partials/topics_and_members_counts.html" with node=child %} -
    -
  • - {% endfor %} -
-
- {% endif %} -
-
- {% endfor %} - {% elif forum_contents.top_nodes.0.obj.is_in_documentation_area %} -
- {% for node in forum_contents.top_nodes %} -
- -
- {% endfor %} -
- {% else %} - - {% endif %} -{% endif %} diff --git a/lacommunaute/templates/forum/index.html b/lacommunaute/templates/forum/index.html index 5e254078e..14256719f 100644 --- a/lacommunaute/templates/forum/index.html +++ b/lacommunaute/templates/forum/index.html @@ -2,6 +2,7 @@ {% load i18n %} {% load mptt_tags %} {% load forum_tags %} +{% load str_filters %} {% block title %} {% trans "Index" %}{{ block.super }} {% endblock %} @@ -9,7 +10,49 @@
-
{% forum_list forums %}
+
+ {% for node in forums.top_nodes %} +
+
+ {% if node.obj.image %} +
+ {{ node.obj.name }} +
+ {% endif %} +
+

+ {{ node.obj.name }} +

+

{% include "forum/partials/topics_and_members_counts.html" %}

+
+
+
+ {% if node.obj.description.rendered %}{{ node.obj.description.rendered|urlizetrunc_target_blank:30 }}{% endif %} + {% if node.children %} + +
+
    + {% for child in node.children %} +
  • +
    + {{ child.obj.name }} + {% include "forum/partials/topics_and_members_counts.html" with forum=child %} +
    +
  • + {% endfor %} +
+
+ {% endif %} +
+
+ {% endfor %} +
diff --git a/lacommunaute/utils/testing.py b/lacommunaute/utils/testing.py index a1a503895..b60ab81e0 100644 --- a/lacommunaute/utils/testing.py +++ b/lacommunaute/utils/testing.py @@ -1,6 +1,7 @@ import importlib from bs4 import BeautifulSoup +from django.db import connection from django.test.utils import TestContextDecorator @@ -18,7 +19,7 @@ def disable(self): setattr(self._module, key, value) -def parse_response_to_soup(response, selector=None, no_html_body=False, replace_in_href=None): +def parse_response_to_soup(response, selector=None, no_html_body=False, replace_in_href=None, replace_img_src=False): soup = BeautifulSoup(response.content, "html5lib", from_encoding=response.charset or "utf-8") if no_html_body: # If the provided HTML does not contain tags @@ -45,4 +46,27 @@ def parse_response_to_soup(response, selector=None, no_html_body=False, replace_ for attr in ["href", "hx-post"]: for links in soup.find_all(attrs={attr: True}): [links.attrs.update({attr: links.attrs[attr].replace(*replacement)}) for replacement in replacements] + if replace_img_src: + for attr in ["src"]: + for links in soup.find_all("img", attrs={attr: True}): + links.attrs.update({attr: "[img src]"}) return soup + + +def reset_model_sequence_fixture(*model_classes): + """ + :return: a function which can adjust and reset a primary key sequence for use as a pytest fixture + it is used to temporarily change the primary key, so that it is predictable (e.g. for snapshots) + """ + + def reset_model_sequence(): + def set_sequence_value(cursor, value): + cursor.execute( + "SELECT setval(pg_get_serial_sequence(%s, 'id'), %s, false);", (model_class._meta.db_table, str(value)) + ) + + with connection.cursor() as cursor: + for model_class in model_classes: + set_sequence_value(cursor, 9999) + + return reset_model_sequence