Exemplo n.º 1
0
def generate_blog_post():
    post = BlogPost()
    post.name = random.choice(long_actions)
    post.content = user_description
    post.date = generate_datetime()
    post.published = True
    post.save()
Exemplo n.º 2
0
    def test_save_and_retrieve_blog_posts(self):
        self.assertEqual(BlogPost.objects.all().count(), 0)
        blog_post = BlogPost()
        blog_post.title = "A post"
        blog_post.date = datetime.datetime(1939, 9, 1, 5, 0, 0)
        blog_post.body = "Blah blah blah"
        blog_post.visible = False
        blog_post.save()
        self.assertEqual(BlogPost.objects.all().count(), 1)

        retrieved_post = BlogPost.objects.first()
        self.assertEqual(retrieved_post, blog_post)
Exemplo n.º 3
0
    def test_save_and_retrieve_blog_posts(self):
        self.assertEqual(BlogPost.objects.all().count(), 0)
        blog_post = BlogPost()
        blog_post.title = "A post"
        blog_post.date = datetime.datetime(1939, 9, 1, 5, 0, 0)
        blog_post.body = "Blah blah blah"
        blog_post.visible = False
        blog_post.save()
        self.assertEqual(BlogPost.objects.all().count(), 1)

        retrieved_post = BlogPost.objects.first()
        self.assertEqual(retrieved_post, blog_post)
Exemplo n.º 4
0
def load_education_blog_posts():
    """
    Transferring blog posts from EdCentral CSV
    for Education Policy Program
    """
    education_blog_mapping = edcentral_blog_mapping()

    for post in education_blog_mapping:
        if post['title'] == 'title':
            pass
        else:
            print(post['title'])
            post_parent = get_program('5')
            parent_blog_homepage = get_content_homepage(
                post_parent,
                ProgramBlogPostsPage,
                'EdCentral',
            )
            ed_blog_post_slug = post['slug']
            print(ed_blog_post_slug)
            new_blog_post = BlogPost.objects.filter(
                slug=ed_blog_post_slug).first()

            if not new_blog_post and ed_blog_post_slug:
                new_blog_post = BlogPost(
                    search_description='',
                    seo_title='',
                    depth=5,
                    show_in_menus=False,
                    slug=ed_blog_post_slug,
                    title=post['title'],
                    date=post['real_date'],
                    body=json.dumps([{
                        'type': 'paragraph',
                        'value': post['content']
                    }]),
                    story_excerpt=get_summary(post['excerpt']),
                )
                parent_blog_homepage.add_child(instance=new_blog_post)
                new_blog_post.save()
                print(
                    "-------------------ADDED NEW EDCENTRAL POST----------------------"
                )
                get_education_authors(new_blog_post, post['author'])
                connect_subprograms_to_post(
                    new_blog_post,
                    clean_subprograms_for_ed(post['categories']))
            elif new_blog_post and ed_blog_post_slug:
                new_blog_post.search_description = ''
                new_blog_post.seo_title = ''
                new_blog_post.depth = 5
                new_blog_post.show_in_menus = False
                new_blog_post.slug = ed_blog_post_slug
                new_blog_post.title = post['title']
                new_blog_post.date = post['real_date']
                new_blog_post.body = json.dumps([{
                    'type': 'paragraph',
                    'value': post['content']
                }])
                new_blog_post.story_excerpt = get_summary(post['excerpt'])
                get_education_authors(new_blog_post, post['author'])
                connect_subprograms_to_post(
                    new_blog_post,
                    clean_subprograms_for_ed(post['categories']))
                print(
                    "-------------------UPDATED EXISTING EDCENTRAL POST----------------------"
                )
                new_blog_post.save()