Example #1
0
def root_page():
    """
    Get the global Wagtail root page (cleared of any subpages it might have)
    :return: Root page
    :rtype: wagtail.wagtailcore.models.Page
    """
    try:
        page = Page.objects.get(slug="root", depth=1)
    except Page.DoesNotExist:  # pragma: no cover
        page = Page.objects.create(
            title="Root",
            slug='root',
            content_type=ContentType.objects.get_for_model(Page),
            path='0001',
            depth=1,
            numchild=1,
            url_path='/',
        )

    for child in page.get_children():  # pragma: no cover
        child.delete()
    page.numchild = 0
    page.save(update_fields=("numchild", ))

    site = Site.objects.first()
    if not site:  # pragma: no cover
        site = Site()
    site.root_page = page
    site.is_default_site = True
    site.save()

    return page
Example #2
0
    def setUp(self):
        p = Page()
        p.title = 'Root Page'
        p.slug = 'root-page'
        p.depth = 0
        p.save()

        s = Site()
        s.root_page = p
        s.is_default_site = True
        s.hostname = 'localhost'
        s.port = 80
        s.save()