Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
]
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions core/home/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Comment on lines 6 to 12
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import grouping/order here looks like it will be reformatted by isort (CI runs pre-commit with isort). Consider running isort or reorganizing imports so local-app imports (collection/journal/core.*) are in a single section and sorted consistently, rather than splitting core.home.* into a separate block.

Suggested change
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
from core.home.models import AboutScieloOrgPage, HomePage
from core.home.views import _get_scielo_journals_data
from core.users.models import User
from journal.models import Journal, SciELOJournal

Copilot uses AI. Check for mistakes.
class TestSubpageAdminDefaultOrdering(TestCase):
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test class only asserts model class attributes and doesn’t use the database; using django.test.SimpleTestCase instead of TestCase would avoid unnecessary DB setup and speed the suite (you’d also need to adjust the import at the top accordingly).

Copilot uses AI. Check for mistakes.
"""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")
Comment on lines +25 to +29
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests verify that admin_default_ordering is set, but they don’t actually exercise the regression scenario described in the PR (a subpage moving to the top of the Wagtail admin children listing after edit/publish). Consider adding an integration-style assertion that creates sibling pages, simulates an edit/publish to update latest_revision_created_at, and verifies the admin listing order remains tree/path-based.

Copilot uses AI. Check for mistakes.


class TestGetScieloJournalsData(TestCase):
def setUp(self):
self.user = User.objects.create(username="testuser", password="testpass")
Expand Down