diff --git a/core/home/models.py b/core/home/models.py index 7befa852..0bbadd03 100755 --- a/core/home/models.py +++ b/core/home/models.py @@ -170,6 +170,12 @@ class HomePage(Page): "home.ListPageJournalByCategory", ] + # Show child pages in their tree (manual) order in the Wagtail admin + # listing, instead of by latest revision date. This keeps the order + # stable when an editor edits a subpage and matches what is shown on + # the public-facing site (which uses `get_children`, ordered by path). + admin_default_ordering = "ord" + content_panels = Page.content_panels + [ InlinePanel("sponsors", label=_("Footer Sponsors"), heading=_("Patrocinadores do Footer")), ] @@ -352,6 +358,13 @@ class Meta: class AboutScieloOrgPage(Page): subpage_types = ["home.AboutScieloOrgPage"] + # Preserve the manual (tree) order of subpages in the Wagtail admin + # listing. Without this, Wagtail's default ``-latest_revision_created_at`` + # ordering causes the most recently edited subpage to jump to the top + # of the list, breaking the predefined order (see issue: "Edição de + # páginas causa reordenamento dos itens"). + admin_default_ordering = "ord" + body = RichTextField(_("Body"), blank=True) external_link = models.URLField( _("Link externo"), blank=True, null=True, max_length=2000 diff --git a/core/home/tests.py b/core/home/tests.py index 19b77133..5174c90f 100644 --- a/core/home/tests.py +++ b/core/home/tests.py @@ -6,9 +6,29 @@ from core.users.models import User from journal.models import Journal, SciELOJournal +from core.home.models import AboutScieloOrgPage, HomePage from core.home.views import _get_scielo_journals_data +class TestSubpageAdminDefaultOrdering(TestCase): + """Regression tests for issue: + "Edição de páginas causa reordenamento dos itens". + + Wagtail's default ``admin_default_ordering`` of + ``-latest_revision_created_at`` would cause a recently edited subpage + to jump to the top of the children listing in the admin, breaking + the predefined order. The fix sets ``admin_default_ordering = "ord"`` + on the relevant page models so that children are always listed in + their tree (manual) order, matching the public-facing site. + """ + + def test_about_scielo_org_page_uses_tree_ordering_in_admin(self): + self.assertEqual(AboutScieloOrgPage.admin_default_ordering, "ord") + + def test_home_page_uses_tree_ordering_in_admin(self): + self.assertEqual(HomePage.admin_default_ordering, "ord") + + class TestGetScieloJournalsData(TestCase): def setUp(self): self.user = User.objects.create(username="testuser", password="testpass")