def _add_blog_index_page_as_root_child_page(
         self,
         title=index_page_title,
         meta_description=index_page_description,
         keywords=index_page_keywords):  # pylint: disable=no-self-use
     blog_index_page = BlogIndexPage(title=title,
                                     meta_description=meta_description,
                                     keywords=keywords)
     Page.objects.get(title="Root").add_child(instance=blog_index_page)
     blog_index_page.save()
     return blog_index_page
示例#2
0
def index_pages():
    home = home_page()
    events_index = home.add_child(
        instance=EventsIndexPage(title='Test Events Index', live=True))
    about_index = home.add_child(
        instance=AboutUsIndexPage(title='Test About Index', live=True))
    github_index = home.add_child(
        instance=GithubOrgIndexPage(title='Test Github Index', live=True))
    project_index = home.add_child(
        instance=ProjectIndexPage(title='Test Project Index', live=True))
    api_index = home.add_child(
        instance=APIIndexPage(title='Test API Index', live=True))
    blog_index = home.add_child(
        instance=BlogIndexPage(title='Test Blog Index', live=True))

    return [
        home, events_index, about_index, github_index, project_index,
        api_index, blog_index
    ]
示例#3
0
def index_pages():
    home = home_page()
    blog_index = home.add_child(
        instance=BlogIndexPage(title='Test Blog Index', live=True))

    return [home, blog_index]
示例#4
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',
        )
示例#5
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()