Ejemplo n.º 1
0
 def setUp(self):
     self.login()
     self.root_page = Page.objects.get(id=1)
     self.home_page = self.root_page.add_child(instance=HomePage(
         title='New America'))
     self.all_quoted_home_page = self.home_page.add_child(
         instance=AllQuotedHomePage(title='New America In The News'))
     self.program_page_1 = self.home_page.add_child(
         instance=Program(title='OTI',
                          name='OTI',
                          description='OTI',
                          location=False,
                          depth=3))
     self.second_program = self.home_page.add_child(
         instance=Program(title='Education',
                          name='Education',
                          slug='education',
                          description='Education',
                          location=False,
                          depth=3))
     self.program_quoted_page = self.program_page_1\
         .add_child(instance=ProgramQuotedPage(
             title='OTI In The News')
         )
     self.quoted = Quoted(title='Quoted 1',
                          slug='quoted-1',
                          date='2016-02-10',
                          depth=5)
     self.program_quoted_page.add_child(instance=self.quoted)
     self.quoted.save()
Ejemplo n.º 2
0
 def setUp(self):
     self.login()
     self.root_page = Page.objects.get(id=1)
     self.home_page = self.root_page.add_child(instance=HomePage(
         title='New America'))
     self.all_events_home_page = self.home_page.add_child(
         instance=AllEventsHomePage(title="All Events at New America!"))
     self.program_page_1 = self.home_page.add_child(
         instance=Program(title='OTI',
                          name='OTI',
                          description='OTI',
                          location=False,
                          depth=3))
     self.second_program = self.home_page.add_child(
         instance=Program(title='Education',
                          name='Education',
                          slug='education',
                          description='Education',
                          location=False,
                          depth=3))
     self.program_events_page = self.program_page_1.add_child(
         instance=ProgramEventsPage(title='OTI Events'))
     self.event = self.program_events_page.add_child(
         instance=Event(title='Event 1',
                        date='2016-02-10',
                        rsvp_link='http://www.newamerica.org',
                        soundcloud_url='http://www.newamerica.org'))
Ejemplo n.º 3
0
    def setUpClass(cls):
        # set up root page if there isn't any,
        cls.root = Page.objects.get(title="Root") if Page.objects.first() else Page.objects.create(
            title="Root",
            path="001",
            depth=1,
        )

        # set up 'Site' object if there isn't any
        cls.site = Site.objects.first() if Site.objects.first() else Site.objects.create(
            site_name="localhost",
            is_default_site=True,
            root_page=cls.root,
        )

        # Set up home page
        cls.home_page = HomePage(title=site_main_title)
        # publish the home page!
        cls.root.add_child(instance=cls.home_page).save_revision().publish()

        # don't forget to make the home page the root page of the Site object
        cls.site.root_page = cls.home_page
        cls.site.save()

        super(Main, cls).setUpClass()
Ejemplo n.º 4
0
    def handle(self, *args, **options):
        root_page = Page.objects.get(id=1)
        home_page = HomePage(title="Welcome")

        root_page.add_child(instance=home_page)
        root_page.save()

        community_page = CommunityPage(title="Community")
        magazine_index_page = MagazineIndexPage(title="Magazine")

        home_page.add_child(instance=community_page)
        home_page.add_child(instance=magazine_index_page)
        home_page.save()

        # Magazine section
        magazine_department_index_page = MagazineDepartmentIndexPage(
            title="Departments")
        magazine_tag_index_page = MagazineTagIndexPage(title="Tags")

        magazine_index_page.add_child(instance=magazine_department_index_page)
        magazine_index_page.add_child(instance=magazine_tag_index_page)
        magazine_index_page.save()

        # Community section
        meeting_index_page = MeetingIndexPage(title="Meetings")
        organization_index_page = OrganizationIndexPage(title="Organizations")
        person_index_page = PersonIndexPage(title="People")

        community_page.add_child(instance=meeting_index_page)
        community_page.add_child(instance=organization_index_page)
        community_page.add_child(instance=person_index_page)
        community_page.save()

        self.stdout.write("All done!")
Ejemplo n.º 5
0
 def setUp(self):
     """Test."""
     root_site = Site.objects.get(is_default_site=True)
     root_page = Page.objects.get(id=root_site.root_page_id)
     page = HomePage(title="Testpage")
     root_page.add_child(instance=page)
     self.page = page
Ejemplo n.º 6
0
 def setUp(self):
     self.images = [f for f in os.listdir(MEDIA_ROOT + '/original_images') ]
     self.image_files = []
     self.count = 0
     self.count += len([name for name in os.listdir('./media/images')])
     self.count += len([name for name in os.listdir('./media/original_images')])
     for page in Page.objects.all():
         if page.is_root():
             root = page
             break
     slug = "landingPage"
     path = "test/" + slug
     home_page = HomePage(path=path, depth=2, slug=slug, title="HomePage")
     root.add_child(instance=home_page)
     home_page.save()
     for i in range(4):
         self.create_page(i, home_page)
     for image in self.images[:10]:
         self.create_image(image)
     main_image = ImageSelector.objects.get(id=10).main_image
     json_dic = {"create":
                     {"-1":{"tags":["Wasserfall"],"x":759,"y":425,"width":268,"height":537}},
                 "delete":[],
                 "alter":[]}
     main_image.json = json_dic
     main_image.save()
Ejemplo n.º 7
0
 def setUp(self):
     self.login()
     self.root_page = Page.objects.get(id=1)
     self.home_page = self.root_page.add_child(instance=HomePage(
         title='New America'))
     self.all_press_releases_home_page = self.home_page.add_child(
         instance=AllPressReleasesHomePage(
             title='New America Press Releases'))
     self.program_page_1 = self.home_page.add_child(
         instance=Program(title='OTI',
                          name='OTI',
                          description='OTI',
                          location=False,
                          depth=3))
     self.second_program = self.home_page.add_child(
         instance=Program(title='Education',
                          name='Education',
                          slug='education',
                          description='Education',
                          location=False,
                          depth=3))
     self.program_press_releases_page = self.program_page_1\
         .add_child(instance=ProgramPressReleasesPage(
             title='OTI Press Releases')
         )
     self.press_release = PressRelease(title='Press Release 1',
                                       slug='press-release-1',
                                       date='2016-02-10',
                                       depth=5)
     self.program_press_releases_page.add_child(instance=self.press_release)
     self.press_release.save()
Ejemplo n.º 8
0
    def handle(self, *args, **options):
        if options['delete']:
            Page.objects.filter(slug='home').delete()

        try:
            HomePage.objects.get(slug='home')
        except ObjectDoesNotExist:
            Page.objects.filter(slug='home').delete()
            home_page = HomePage(title='Home', slug='home')

            root_page = Page.objects.get(title='Root')
            root_page.add_child(instance=home_page)

            Site.objects.create(site_name='project_name (Dev)',
                                hostname='localhost',
                                port='8000',
                                root_page=home_page,
                                is_default_site=True)

            # Certain apps (allauth, for example) use the django rather than
            # Wagtail site name and are not overridable.
            django_site = DjangoSite.objects.first()
            django_site.domain = 'www.project_name.com'
            django_site.name = 'project_name'
            django_site.save()
Ejemplo n.º 9
0
 def setUp(self):
     self.login()
     self.root_page = Page.objects.get(id=1)
     self.home_page = self.root_page.add_child(instance=HomePage(
         title='New America'))
     self.program_page = self.home_page.add_child(
         instance=Program(title='OTI',
                          name='OTI',
                          description='OTI',
                          location=False,
                          depth=3))
     self.subprogram_page = self.program_page.add_child(instance=Subprogram(
         title='OTI Subprogram',
         name='OTI Subprogram',
         description='OTI Subprogram',
         location=False,
         depth=4,
     ))
     self.program_articles_page = self.program_page.add_child(
         instance=ProgramArticlesPage(title='Program Articles'))
     self.article = self.program_articles_page.add_child(
         instance=Article(title='Article 1', date='2016-02-02'))
     self.subprogram_articles_page = self.subprogram_page.add_child(
         instance=ProgramArticlesPage(title='Subprogram Articles'))
     self.subprogram_article = self.subprogram_articles_page.add_child(
         instance=Article(title='Article 2', date='2016-02-03'))
Ejemplo n.º 10
0
 def setUp(self):
     self.login()
     self.root_page = Page.objects.get(id=1)
     self.home_page = self.root_page.add_child(instance=HomePage(
         title='New America'))
     self.all_policy_papers_home_page = self.home_page.add_child(
         instance=AllPolicyPapersHomePage(
             title='New America Policy Papers'))
     self.program_page_1 = self.home_page.add_child(
         instance=Program(title='OTI',
                          name='OTI',
                          description='OTI',
                          location=False,
                          depth=3))
     self.second_program = self.home_page.add_child(
         instance=Program(title='Education',
                          name='Education',
                          slug='education',
                          description='Education',
                          location=False,
                          depth=3))
     self.program_policy_papers_page = self.program_page_1\
         .add_child(instance=ProgramPolicyPapersPage(
             title='OTI Policy Papers')
         )
     self.policy_paper = PolicyPaper(title='Policy Paper 1',
                                     slug='policy-paper-1',
                                     date='2016-02-10',
                                     depth=5)
     self.program_policy_papers_page.add_child(instance=self.policy_paper)
     self.policy_paper.save()
Ejemplo n.º 11
0
    def setUp(self):
        self.login()
        site = Site.objects.get()
        page = Page.get_first_root_node()
        home = HomePage(title='New America')
        self.home_page = page.add_child(instance=home)

        site.root_page = home
        site.save()

        self.our_people_page = self.home_page.add_child(
            instance=OurPeoplePage(title='Our People', depth=3))
        self.program_page = self.home_page.add_child(
            instance=Program(title='OTI',
                             name='OTI',
                             description='OTI',
                             location=False,
                             depth=3))
        self.second_program = self.home_page.add_child(
            instance=Program(title='Education',
                             name='Education',
                             slug='education',
                             description='Education',
                             location=False,
                             depth=3))
        self.subprogram_page = self.program_page.add_child(
            instance=Subprogram(title='OTI Subprogram',
                                name='OTI Subprogram',
                                description='OTI Subprogram',
                                location=False,
                                depth=4))
        self.second_subprogram_page = self.program_page.add_child(
            instance=Subprogram(title='OTI Subprogram 2',
                                name='OTI Subprogram 2',
                                description='OTI Subprogram 2',
                                location=False,
                                depth=4))
        self.program_articles_page = self.program_page.add_child(
            instance=ProgramArticlesPage(title='Program Articles'))
        self.test_person = Person(
            title='Sana Javed',
            slug='sana-javed',
            first_name='Sana',
            last_name='Javed',
            role='Central Staff',
            depth=4,
        )
        self.our_people_page.add_child(instance=self.test_person)
        self.test_person.save()

        self.article = self.program_articles_page.add_child(
            instance=Article(title='Article 1', date='2016-02-02'))
        PostAuthorRelationship(author=self.test_person,
                               post=self.article).save()

        self.article_2 = self.program_articles_page.add_child(
            instance=Article(title='Article 2', date='2016-05-02'))
        PostAuthorRelationship(author=self.test_person,
                               post=self.article_2).save()
Ejemplo n.º 12
0
    def create_homepage():
        site = Site.objects.get()
        page = Page.get_first_root_node()
        home = HomePage(title='New America')
        home_page = page.add_child(instance=home)

        site.root_page = home
        site.save()

        return home_page
Ejemplo n.º 13
0
def register_centers(user):
    '''
    Utility function for registering the three available centres into the
    database.
    '''

    centre_parent_page = None

    try:
        centre_parent_page = HomePage.objects.get(title='sentre')
    except HomePage.DoesNotExist:
        centre_parent_page = HomePage(title='sentre',
                                      slug='sentre',
                                      show_in_menus=True)
        site_root_page = Page.get_root_nodes()[0]
        main_page = site_root_page.get_children()[0]
        main_page.add_child(instance=centre_parent_page)

    centres = ((dict(
        code='KTL',
        slug='ktl',
        title='Karma Tashi Ling',
        address='Bjørnåsveien 124, 1272 Oslo',
        map_query=('pb=!1m18!1m12!1m3!1d64085.02466250845!2d10.719858097203817'
                   '!3d59.8714410155457!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.'
                   '1!3m3!1m2!1s0x4641689e9e629ca3%3A0x659a4f081752df6d!2s'
                   'Karma+Tashi+Ling+buddhistsamfunn!5e0!3m2!1sen!2sus'
                   '!4v1474500703908'),
        tlf='22 61 28 84'
    ), 'Vårt hovedsenter med tempelbygg og fredsstupa.'), (dict(
        code='RZS',
        slug='rzs',
        title='Rinzai Zen Center',
        address='Grønlandsleiret 31, 0190 Oslo',
        map_query=('pb=!1m18!1m12!1m3!1d2000.2561350426204!2d10.76453441642817'
                   '3!3d59.9112963818663!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13'
                   '.1!3m3!1m2!1s0x46416e5f5dc234eb%3A0x73571e2cd774d684!2sRin'
                   'zai+Zen+Center!5e0!3m2!1sen!2sno!4v1566137504814!5m2!1sen!'
                   '2sno'),
        tlf=None), 'Bysenter.'), (dict(
            code='KSL',
            slug='ksl',
            title='Karma Shedrup Ling retreatsenter',
            map_query=(
                'pb=!1m18!1m12!1m3!1d2009.7581754898429!2d10'
                '.927372341251292!3d59.75346552497313!2m3!1f0!2f0!3f0!3m2'
                '!1i1024!2i768!4f13.1!3m3!1m2!1s0x46415df5da495a43'
                '%3A0xd9ab4ea8e930b13d!2sKarma+Shedrup+Ling+retreatsenter'
                '!5e0!3m2!1sen!2sus!4v1474500473508'),
            address='Siggerudveien 734, 1400 Ski',
            tlf=None), 'Retreatsenter i Sørmarka.'))

    for centre_data in centres:
        create_center(centre_data, centre_parent_page, user)
        logger.info('registerred centre: "{}"'.format(centre_data[0]['title']))
Ejemplo n.º 14
0
 def setUp(self):
     self.login()
     self.root_page = Page.objects.get(id=1)
     self.home_page = self.root_page.add_child(instance=HomePage(
         title='New America'))
     self.program_page_1 = self.home_page.add_child(
         instance=Program(title='OTI',
                          name='OTI',
                          description='OTI',
                          location=False,
                          depth=3))
Ejemplo n.º 15
0
    def setUp(self):
        self.login()
        site = Site.objects.get()
        page = Page.get_first_root_node()
        home = HomePage(title='New America')
        home_page = page.add_child(instance=home)

        site.root_page = home
        site.save()

        # People objects to test template tags
        # that create byline and determine author order
        program_page_1 = home_page.add_child(
            instance=Program(title='OTI',
                             name='OTI',
                             slug='oti',
                             description='OTI',
                             location=False,
                             depth=3))
        program_page_1.save()

        our_people_page = home_page.add_child(instance=OurPeoplePage(
            title='Our People',
            depth=3,
        ))
        our_people_page.save()

        self.first_person = Person(
            title='First Person',
            slug='first-person',
            first_name='first',
            last_name='person',
            role='Central Staff',
            depth=4,
        )
        our_people_page.add_child(instance=self.first_person)

        # Using policy papers to test the other post types
        all_policy_papers_home_page = home_page.add_child(
            instance=AllPolicyPapersHomePage(title="Policy Papers"))

        program_policy_papers_page = program_page_1.add_child(
            instance=ProgramPolicyPapersPage(title='OTI Policy Papers',
                                             slug='oti-policy-papers'))
        self.policy_paper = PolicyPaper(title='Policy Paper 1',
                                        slug='policy-paper-1',
                                        date='2016-06-15',
                                        depth=5)
        program_policy_papers_page.add_child(instance=self.policy_paper)
        self.policy_paper.save()
        PostAuthorRelationship(author=self.first_person,
                               post=self.policy_paper).save()
        all_policy_papers_home_page.save()
Ejemplo n.º 16
0
    def handle(self, *args, **options):
        root_page = Page.objects.get(id=1)
        home_page = HomePage(title="Welcome")

        root_page.add_child(instance=home_page)
        root_page.save()

        # Set Home Page as root page for Site
        site = Site.objects.get(id=1)
        site.root_page = home_page
        site.save()

        # TODO: see if root_page can now be deleted

        community_page = CommunityPage(title="Community")
        magazine_index_page = MagazineIndexPage(title="Magazine")

        home_page.add_child(instance=community_page)
        home_page.add_child(instance=magazine_index_page)
        home_page.save()

        # Magazine section
        magazine_department_index_page = MagazineDepartmentIndexPage(
            title="Departments")
        magazine_tag_index_page = MagazineTagIndexPage(title="Tags")
        deep_archive_index_page = DeepArchiveIndexPage(title="Archive")

        magazine_index_page.add_child(instance=magazine_department_index_page)
        magazine_index_page.add_child(instance=magazine_tag_index_page)
        magazine_index_page.add_child(instance=deep_archive_index_page)

        magazine_index_page.save()

        # Community section
        meeting_index_page = MeetingIndexPage(title="Meetings")
        organization_index_page = OrganizationIndexPage(title="Organizations")
        person_index_page = PersonIndexPage(title="People")

        community_page.add_child(instance=meeting_index_page)
        community_page.add_child(instance=organization_index_page)
        community_page.add_child(instance=person_index_page)
        community_page.save()

        self.stdout.write("All done!")
Ejemplo n.º 17
0
    def setUp(self):

        home_page = HomePage(
            title="test",
            depth=2,
            path="00010002")
        home_page.save()

        movie_page = MoviePage(
            title="Jojo Rabbit",
            depth=3,
            path="000100020001",
        )
        movie_page.save()

        from django.utils import timezone

        movie_date_1 = Moviedate(
            page=movie_page,
            date=timezone.datetime(year=2020, month=11, day=29, hour=20, minute=30)
        )
        movie_date_1.save()
        self.movie_movie_date_id = movie_date_1.id

        from persistent.serializer import JsonSerializer
        mg = MailGunConnectionSettings(
            domain='sandboxdcf43d206af14bfea97d9935782f6cc4.mailgun.org',
            privateKey='key-7ecc7c60f368bdef2f5f84fba4145423',
            publicKey='pubkey-cc185b9df1e0a47d3b50be5d24c242f1'
        )

        mail_server_connection = MailServerConnection(
            name="sandbox.mailgun.org"
        )
        mail_server_connection.set_object(mg)
        mail_server_connection.save()

        mail_sender = MailSender(
            name="rkzbios",
            mailServerConnection=mail_server_connection
        )
        mail_sender.save()
Ejemplo n.º 18
0
def test_block_type_change(root_page, get_migration_executor):
    stream_data = [{
        "type": "title",
        "value": "Heading 1"
    }, {
        "type": "paragraph",
        "value": "abcdef"
    }]
    stream_block = HomePage.body.field.stream_block
    body = StreamValue(stream_block, [],
                       is_lazy=True,
                       raw_text=json.dumps(stream_data))
    root_page.add_child(instance=HomePage(title="test", body=body))

    get_migration_executor().migrate([("home", "0003_rename_title_to_heading")
                                      ])

    homepage = HomePageAfterMigration.objects.get(title="test")
    heading_block = homepage.body[0]
    assert heading_block.block_type == "heading"
    assert heading_block.value == "Heading 1"
Ejemplo n.º 19
0
 def setUp(self):
     self.login()
     self.root_page = Page.objects.get(id=1)
     self.home_page = self.root_page.add_child(instance=HomePage(
         title='New America'))
     self.program_page_1 = self.home_page.add_child(
         instance=Program(title='OTI',
                          name='OTI',
                          description='OTI',
                          location=False,
                          depth=3))
     self.second_program = self.home_page.add_child(
         instance=Program(title='Education',
                          name='Education',
                          slug='education',
                          description='Education',
                          location=False,
                          depth=3))
     self.program_blog_posts_page = self.program_page_1.add_child(
         instance=ProgramBlogPostsPage(title='OTI Blog'))
     self.blog_post = self.program_blog_posts_page.add_child(
         instance=BlogPost(title='Blog Post 1', date='2016-02-10'))
Ejemplo n.º 20
0
    def setUpTestData(cls):
        # Set up root page required if there isn't any
        cls.root = Page.objects.get(title="Root").specific if Page.objects.count() > 0 else Page.objects.create(
            title="Root",
            path="001",
            depth=1,
        )

        # Set up home page and make it child of root page
        cls.home_page = HomePage(title=site_main_title)
        cls.root.add_child(instance=cls.home_page).save_revision().publish()

        # set up Site object if there isn't any
        cls.site = Site.objects.first() if Site.objects.first().site_name == "localhost" else Site.objects.create(
            site_name="localhost",
            is_default_site=True,
            root_page=cls.home_page,
        )

        cls.site.root_page = cls.home_page  # watch for necessity
        cls.site.save()  # watch for necessity

        super(Main, cls).setUpTestData()
Ejemplo n.º 21
0
 def setUp(self):
     self.login()
     self.root_page = Page.objects.get(id=1)
     self.home_page = self.root_page.add_child(instance=HomePage(
         title='New America'))
     self.all_podcasts_home_page = self.home_page.add_child(
         instance=AllPodcastsHomePage(title="All Podcasts at New America!"))
     self.program_page_1 = self.home_page.add_child(
         instance=Program(title='OTI',
                          name='OTI',
                          description='OTI',
                          location=False,
                          depth=3))
     self.second_program = self.home_page.add_child(
         instance=Program(title='Education',
                          name='Education',
                          slug='education',
                          description='Education',
                          location=False,
                          depth=3))
     self.program_podcasts_page = self.program_page_1.add_child(
         instance=ProgramPodcastsPage(title='OTI Podcasts'))
     self.podcast = self.program_podcasts_page.add_child(
         instance=Podcast(title='Podcast 1', date='2016-02-10'))
Ejemplo n.º 22
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")
Ejemplo n.º 23
0
def home_page():
    return root_page().add_child(
        instance=HomePage(title='Test Home', live=True))
    def handle(self, *args, **options):
        root_page = Page.objects.get(id=1)
        home_page = HomePage(title="Welcome")

        root_page.add_child(instance=home_page)
        root_page.save()

        # Set Home Page as root page for Site
        site = Site.objects.get(id=1)
        site.root_page = home_page
        site.save()

        # Delete welcome page
        # ID: 2 is used, since welcome page is second page created
        # Otherwise, the title "Welcome to your new Wagtail site!" might be useful
        Page.objects.get(id=2).delete()

        # Create Home Page children
        community_page = CommunityPage(title="Community")
        contact_form_page = ContactFormPage(title="Contact")
        donate_page = DonatePage(title="Donate")
        events_page = EventsIndexPage(title="Events")
        library_index_page = LibraryIndexPage(title="Library")
        magazine_index_page = MagazineIndexPage(title="Magazine")
        manage_subscription_page = ManageSubscriptionPage(title="Manage subscription")
        store_index_page = StoreIndexPage(title="Bookstore")
        subscription_index_page = SubscriptionIndexPage(title="Subscribe")

        home_page.add_child(instance=community_page)
        home_page.add_child(instance=contact_form_page)
        home_page.add_child(instance=donate_page)
        home_page.add_child(instance=events_page)
        home_page.add_child(instance=library_index_page)
        home_page.add_child(instance=magazine_index_page)
        home_page.add_child(instance=manage_subscription_page)
        home_page.add_child(instance=store_index_page)
        home_page.add_child(instance=subscription_index_page)
        home_page.save()

        # Magazine section
        magazine_department_index_page = MagazineDepartmentIndexPage(
            title="Departments"
        )
        magazine_tag_index_page = MagazineTagIndexPage(title="Tags")
        deep_archive_index_page = DeepArchiveIndexPage(title="Archive")

        magazine_index_page.add_child(instance=magazine_department_index_page)
        magazine_index_page.add_child(instance=magazine_tag_index_page)
        magazine_index_page.add_child(instance=deep_archive_index_page)

        magazine_index_page.save()

        # Community section
        community_directory_index_page = CommunityDirectoryIndexPage(title="Community directories")
        meeting_index_page = MeetingIndexPage(title="Meetings")
        memorial_index_page = MemorialIndexPage(title="Memorials")
        online_worship_index_page = OnlineWorshipIndexPage(title="Online meetings for worship")
        organization_index_page = OrganizationIndexPage(title="Organizations")
        person_index_page = PersonIndexPage(title="People")

        community_page.add_child(instance=community_directory_index_page)
        community_page.add_child(instance=meeting_index_page)
        community_page.add_child(instance=memorial_index_page)
        community_page.add_child(instance=online_worship_index_page)
        community_page.add_child(instance=organization_index_page)
        community_page.add_child(instance=person_index_page)
        community_page.save()

        # Library section
        facet_index_page = FacetIndexPage(title="Facets")

        library_index_page.add_child(instance=facet_index_page)

        # Library facets section
        audience_index_page = AudienceIndexPage(title="Audience")
        genre_index_page = GenreIndexPage(title="Genre")
        medium_index_page = MediumIndexPage(title="Medium")
        time_period_index_page = TimePeriodIndexPage(title="Time period")
        topic_index_page = TopicIndexPage(title="Topic")

        facet_index_page.add_child(instance=audience_index_page)
        facet_index_page.add_child(instance=genre_index_page)
        facet_index_page.add_child(instance=medium_index_page)
        facet_index_page.add_child(instance=time_period_index_page)
        facet_index_page.add_child(instance=topic_index_page)

        # Bookstore section
        product_index_page = ProductIndexPage(title="Products")

        store_index_page.add_child(instance=product_index_page)

        self.stdout.write("All done!")
Ejemplo n.º 25
0
    def handle(self, *args, **options):
        self.stdout.write('Creating development data... ', '')
        self.stdout.flush()

        # Delete the default home page
        Page.objects.get(slug='home').delete()

        # Basic setup
        root_page = Page.objects.get(title='Root')

        home_page = HomePage(
            title='Home',
            slug='home',
            main_title='Every news site should be secure.',
            sub_title='HTTPS encryption enables security, privacy, and '
                      'prevents censorship. We’re tracking its adoption.',
            why_header='HTTPS protects your privacy and security',
            why_body="With HTTPS enabled by default you can protect reader"
                     " privacy, improve your website's security, better"
                     " protect your sources, prevent censorship, improve"
                     " your search rankings, provide a better user experience,"
                     " see your website loading speeds potentially increase,"
                     " and avoid Google shaming.",
            how_header='Resources for switching your news site over to HTTPS',
            how_body="Switching your news site over to HTTPS is not as simple"
                     " as flicking a switch. But a handful of news "
                     "organizations have already pioneered the effort and "
                     "have shared their tips and tricks for making it as "
                     "smooth as possible. We've documented them here."
        )
        root_page.add_child(instance=home_page)

        site = Site.objects.create(
            site_name='Freedom of the Press (Dev)',
            hostname='localhost',
            port='8000',
            root_page=home_page,
            is_default_site=True
        )

        # Add "Why?" and "How" pages, since they're so prominently featured
        # on the home page.
        why_page = ContentPage(
            title='Why?',
            slug='why',
            sub_header='10 good reasons to switch your site to HTTPS',
            show_in_menus=True
        )
        home_page.add_child(instance=why_page)

        how_page = ContentPage(
            title='How',
            slug='how',
            sub_header='Resources and tips for deploying HTTPS by default',
            show_in_menus=True
        )
        home_page.add_child(instance=how_page)

        # Update the "learn more" links on home page now that we've created the
        # "How" and "Why" pages for them to link to.
        home_page.why_learn_more = why_page
        home_page.how_learn_more = how_page
        home_page.save()

        # Add a BlogIndexPage and an example BlogPost
        blog_index_page = BlogIndexPage(
            title='Blog',
            slug='blog',
            show_in_menus=True
        )
        home_page.add_child(instance=blog_index_page)

        blog_post = BlogPost(
            title='Test Blog Post',
            slug='test-blog-post',
            date=datetime.date.today(),
            byline='Dog with a Blog'
        )
        blog_index_page.add_child(instance=blog_post)

        # Main menu via wagtailmenus
        # Remember: Pages must have `show_in_menus=True` *and* a corresponding
        # MainMenuItem to show up
        main_menu = MainMenu.objects.create(site=site)

        why_menu_item = MainMenuItem.objects.create(  # noqa: F841
            menu=main_menu,
            link_text='Why?',
            link_page=why_page
        )
        how_menu_item = MainMenuItem.objects.create(  # noqa: F841
            menu=main_menu,
            link_text='How',
            link_page=how_page
        )
        blog_index_menu_item = MainMenuItem.objects.create(  # noqa: F841
            menu=main_menu,
            link_text='Blog',
            link_page=blog_index_page
        )

        # Load sites and scans from fixtures
        management.call_command('loaddata', 'dev.json')

        # Create superuser
        User.objects.create_superuser(
            'test',
            '*****@*****.**',
            'test',
        )
Ejemplo n.º 26
0
    def handle(self, *args, **options):
        home = HomePage.objects.all()[0]
        baby_blog = options['baby_blog']
        with transaction.atomic():
            index = BlogIndexPage(title="Eddie's Blog", seo_title="Blog", intro="")
            home.add_child(instance=index)

            cmd = [
                'nav3-list',
                'datePublished'
            ] + [
                os.path.join('public', 'blog', path) for path in os.listdir(os.path.join(baby_blog, 'public', 'blog')) if os.path.isdir(os.path.join(baby_blog, 'public', 'blog', path))
            ]
            # print(baby_blog, cmd)
            p = subprocess.Popen(cmd, cwd=baby_blog, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            (stdout, stderr) = p.communicate() 
            if p.wait() != 0:
                print(stderr)
                raise Exception('nav3-list failed')
            # print(stdout)
            data = json.loads(stdout)
            for post in data:
                title = post['data']['title']
                article = post['data']['article']
                date_published = datetime.datetime.fromisoformat(post['data']['datePublished'].split('+')[0])
                intro = html.unescape(post['data']['description'])
                comments = json.loads(post['data']['comments'])
                slug = post['page'].split('/')[1]
                print(slug, title, date_published, len(comments))

                filename_to_value = {}
                for filename in os.listdir(os.path.join(baby_blog,  'public', 'blog', slug, '_', 'img')):
                    if filename.lower().endswith('.jpg'):
                        full_path = os.path.join(baby_blog, 'public', 'blog',  slug, '_', 'img', filename)
                        image_field = ImageFile(open(full_path, 'rb'), name=filename)
                        image = Image(title=filename, file=image_field)
                        image.save()
                        print(filename, image.pk, image_field.size)
                        filename_to_value[filename] = image.pk

                body = html_to_blocks(article, filename_to_value)
                print(body)
                blog_page= BlogPage(
                    title=title,
                    slug=slug,
                    intro=intro,
                    date=date_published,
                    body=json.dumps(body),
                )
                index.add_child(instance=blog_page)
                for c in comments:
                    print(c)
                    comment = BlogPageComment.objects.create(
                        page=blog_page,
                        date=datetime.datetime.utcfromtimestamp(int(c['id'].split('-')[0])/1000), #datetime.datetime.now(),  # XXX
                        author=c['name'],
                        comment=c['comment']
                    )
                # later when a cms user updates the page manually 
                # there will be no first revision to compare against unless
                # you add a page revision also programmatically.
                
                blog_page.save_revision().publish() 
            index.save_revision().publish() 
            photos = HomePage(title='Photos')
            home.add_child(instance=photos)
            for filename in os.listdir(os.path.join(baby_blog,  'public', 'photos', '_', 'img')):
                if filename.lower().endswith('.jpg'):
                    full_path = os.path.join(baby_blog, 'public', 'photos', '_', 'img', filename)
                    image_field = ImageFile(open(full_path, 'rb'), name=filename)
                    image = Image(title=filename, file=image_field)
                    image.save()
                    print(filename, image.pk, image_field.size)
                    filename_to_value[filename] = image.pk
            home.save_revision().publish() 
            photos.save_revision().publish() 
Ejemplo n.º 27
0
 def create_home_page(cls, title='Test home page', path='1', depth=0):
     root_page = cls.get_root_page()
     home_page = HomePage(title=title, path=path, depth=depth)
     root_page.add_child(instance=home_page)
     home_page.save()
     return home_page
Ejemplo n.º 28
0
    def setUp(self):
        self.login()
        site = Site.objects.get()
        page = Page.get_first_root_node()
        home = HomePage(title='New America')
        home_page = page.add_child(instance=home)

        site.root_page = home
        site.save()

        all_events_home_page = home_page.add_child(instance=AllEventsHomePage(
            title="Events"))
        program_page_1 = home_page.add_child(
            instance=Program(title='OTI',
                             name='OTI',
                             slug='oti',
                             description='OTI',
                             location=False,
                             depth=3))
        program_page_1.save()
        second_program = home_page.add_child(
            instance=Program(title='Education',
                             name='Education',
                             slug='education',
                             description='Education',
                             location=False,
                             depth=3))
        second_program.save()
        program_events_page = program_page_1.add_child(
            instance=ProgramEventsPage(title='OTI Events', slug='oti-events'))
        program_events_page.save()
        second_program_events_page = second_program.add_child(
            instance=ProgramEventsPage(title='Education Events',
                                       slug='education-events'))
        second_program_events_page.save()
        today_event = program_events_page.add_child(
            instance=Event(title='Today Event',
                           date=str(date.today()),
                           rsvp_link='http://www.newamerica.org',
                           soundcloud_url='http://www.newamerica.org'))
        today_event.save()
        future_event = program_events_page.add_child(
            instance=Event(title='Future Event',
                           date=str(date.today() + timedelta(days=5)),
                           rsvp_link='http://www.newamerica.org',
                           soundcloud_url='http://www.newamerica.org'))
        future_event.save()
        past_event = program_events_page.add_child(
            instance=Event(title='Past Event',
                           date=str(date.today() - timedelta(days=5)),
                           rsvp_link='http://www.newamerica.org',
                           soundcloud_url='http://www.newamerica.org'))
        past_event.save()

        second_today_event = second_program_events_page.add_child(
            instance=Event(title='Today Event',
                           date=str(date.today()),
                           rsvp_link='http://www.newamerica.org',
                           soundcloud_url='http://www.newamerica.org'))
        second_today_event.save()
        second_future_event = second_program_events_page.add_child(
            instance=Event(title='Future Event',
                           date=str(date.today() + timedelta(days=5)),
                           rsvp_link='http://www.newamerica.org',
                           soundcloud_url='http://www.newamerica.org'))
        second_future_event.save()
        second_past_event = second_program_events_page.add_child(
            instance=Event(title='Past Event',
                           date=str(date.today() - timedelta(days=5)),
                           rsvp_link='http://www.newamerica.org',
                           soundcloud_url='http://www.newamerica.org'))
        second_past_event.save()