Skip to content

Commit

Permalink
allow a root page to live under the home page (for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwvolo committed Jul 1, 2024
1 parent 9961156 commit 75e7ede
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
17 changes: 17 additions & 0 deletions pages/management/commands/migrate_pages_to_new_root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import json
from django.core.management.base import BaseCommand
from pages.models import HomePage, RootPage


class Command(BaseCommand):
help="Use this to move the pages the currently exist under the home page to the new root. This keeps the homepage under the new root page."

def handle(self, *args, **options):
try:
root = RootPage.objects.first()
except RootPage.DoesNotExist:
root = RootPage.objects.create(title="Home", slug="home")

home = HomePage.objects.first()
home.copy(to=root, recursive=True, copy_revisions=True, keep_live=True)
print("All children of the home page have been moved to the new root.")
9 changes: 5 additions & 4 deletions pages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ class RootPage(Page):

template = 'page.html'
max_count = 1
parent_page_types = ['wagtailcore.Page']
subpage_types = ['pages.FlexPage']
# TODO: we are allowing this to be built as a child of the homepage. Not ideal.
# Once the home page is released, use something to migrate homepage children to root page and remove this parent type.
parent_page_types = ['wagtailcore.Page', 'pages.HomePage']
subpage_types = ['pages.FlexPage'] # which might also require allowing all pages to be children.

def __str__(self):
return self.path
Expand Down Expand Up @@ -573,10 +575,9 @@ class Meta:
'books.BookIndex',
'news.NewsIndex',
'news.PressIndex',
'pages.RootPage',
]

max_count = 1

def __str__(self):
return self.path

Expand Down

0 comments on commit 75e7ede

Please sign in to comment.