init_project.py 1.92 KB
Newer Older
Patrick Kimber's avatar
Patrick Kimber committed
1 2 3 4 5
# -*- encoding: utf-8 -*-
"""
This command is designed to be run multiple times.  It will clear out data, and
then re-insert e.g. for setting up the main menu navigation.
"""
Patrick Kimber's avatar
Patrick Kimber committed
6
from django.core.management import call_command
Patrick Kimber's avatar
Patrick Kimber committed
7 8 9 10 11 12 13 14 15 16
from django.core.management.base import BaseCommand

from block.models import (
    Page,
    PageSection,
    Section,
    Template,
    TemplateSection,
    Url,
)
Patrick Kimber's avatar
Patrick Kimber committed
17
from compose.models import SECTION_BODY, SECTION_CARD, SECTION_SLIDESHOW
Patrick Kimber's avatar
Patrick Kimber committed
18 19 20 21


class Command(BaseCommand):

22 23
    help = "Set-up project"

Patrick Kimber's avatar
Patrick Kimber committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    def init_enquiry_page(self):
        """Initialise the 'enquiry' app to work with the 'compose' app."""
        template_article = Template.objects.get(name="Article")
        thank = Page.objects.init_page(
            "contact", "thankyou", "Thank you", 0, template_article
        )
        thank.refresh_sections_from_template()
        self.stdout.write("{} page created".format(thank.name))
        # contact
        template_contact = Template.objects.init_template(
            "Contact", "compose/contact.html"
        )
        for section_slug in (SECTION_BODY, SECTION_CARD, SECTION_SLIDESHOW):
            section = Section.objects.get(slug=section_slug)
            TemplateSection.objects.init_template_section(
                template_contact, section
            )
Patrick Kimber's avatar
Patrick Kimber committed
41
        contact = Page.objects.init_page(
42 43 44
            Page.CUSTOM,
            "contact",
            "Contact",
Patrick Kimber's avatar
Patrick Kimber committed
45 46
            0,
            template_contact,
47
            is_custom=True,
Patrick Kimber's avatar
Patrick Kimber committed
48
        )
Patrick Kimber's avatar
Patrick Kimber committed
49 50
        contact.refresh_sections_from_template()
        self.stdout.write("{} page created".format(contact.name))
51
        Url.objects.init_reverse_url("Contact", "web.contact")
Patrick Kimber's avatar
Patrick Kimber committed
52
        # Link wizard
Patrick Kimber's avatar
Patrick Kimber committed
53
        Url.objects.init_pages()
54 55 56

    def handle(self, *args, **options):
        self.stdout.write("{}".format(self.help))
Patrick Kimber's avatar
Patrick Kimber committed
57 58
        call_command("init_app_compose")
        self.init_enquiry_page()
59
        self.stdout.write("{} - Complete".format(self.help))