Exemplo n.º 1
0
    def _setup(self):
        Page.objects.filter(id=2).delete()
        root = Page.get_first_root_node()
        homepage = HomePage(
            title="St Louis DSA",
            banner_title="Welcome to St Louis DSA!",
            mission_statement=fake.sentence(10),
            values_statement=fake.sentence(10),
            highlighted_campaign=f"{' '.join(fake.words(2)).title()} Campaign",
            highlighted_description=fake.paragraph(5),
        )
        root.add_child(instance=homepage)
        site = Site(
            hostname="localhost",
            root_page=homepage,
            is_default_site=True,
            site_name="stldsa.org",
        )
        site.save()

        newsindexpage = NewsIndexPage(
            title="Updates",
            slug="updates",
            show_in_menus=True,
        )
        homepage.add_child(instance=newsindexpage)
        newsindexpage.has_children_in_menu = False
        newsindexpage.sub_menu = None

        NewsPage = apps.get_model("news.NewsPage")
        newspage = NewsPage(
            title=fake.sentence(),
            main_story_heading=fake.sentence(),
            main_story_copy=fake.paragraph(10),
            related_stories=[
                (
                    "related_story",
                    {
                        "heading": fake.sentence(4),
                        "copy": fake.paragraph(5),
                    },
                ),
                (
                    "related_story",
                    {
                        "heading": fake.sentence(4),
                        "copy": fake.paragraph(4),
                    },
                ),
            ],
            show_in_menus=False,
        )
        newsindexpage.add_child(instance=newspage)

        event_menu_page = EventsPage(title="Events",
                                     show_in_menus=True,
                                     link_url="/events/")
        homepage.add_child(instance=event_menu_page)
        formation_index = InfoPage(title="All Formation Groups",
                                   show_in_menus=True)
        homepage.add_child(instance=formation_index)
        for formation_type_name in [
                "Priority Resolutions",
                "Committees",
                "Working Groups",
                "Caucuses",
        ]:
            formation_type = CommitteesPage(
                title=formation_type_name,
                slug=stringcase.spinalcase(formation_type_name),
                show_in_menus=True,
            )
            formation_index.add_child(instance=formation_type)
            formation_list = CommitteeFactory.build_batch(4)
            for formation in formation_list:
                formation_type.add_child(instance=formation)
                revision = formation.save_revision()
                revision.publish()
                formation.save()

                future_event = Event(
                    title="Event Title",
                    description=fake.paragraph(),
                    start=fake.future_datetime(
                        end_date=datetime.timedelta(days=6),
                        tzinfo=datetime.timezone.utc,
                    ),
                    formation=formation,
                )
                future_event.save()

            revision = formation_type.save_revision()
            revision.publish()
            formation_type.save()
        formation_index.save()

        Group.objects.create(name="Members")
Exemplo n.º 2
0
from django.core.management.base import BaseCommand
from wagtail.models import Page, Site
from events.models import Event, EventsPage
from home.models import HomePage
from news.models import NewsIndexPage, InfoPage
from committees.models import CommitteesPage
from committees.factories import CommitteeFactory
from django.contrib.auth.models import Group

fake = Faker()

User = get_user_model()

logger = logging.getLogger("setup_page_tree")

committee_list = CommitteeFactory.build_batch(8)


class Command(BaseCommand):
    """
    this command is used to create the initial wagtail cms page tree
    """

    help = "creates initial wagtail cms page tree"
    requires_system_checks = False

    def _setup(self):
        Page.objects.filter(id=2).delete()
        root = Page.get_first_root_node()
        homepage = HomePage(
            title="St Louis DSA",