Пример #1
0
    def test_posts(self):
        test_post = Post('Test Post', 'test_post')
        test_post.add_category('Test')
        test_post.add_tags('tag1;tag2')
        test_post.add_body('This is a **test** post.', 'これはテスト書き込みですね。')
        test_post.title_ja = 'テスト書き込み'
        db.session.add(test_post)
        db.session.commit()

        db_test_post = Post.query.filter(Post.slug == 'test_post').first()
        self.assertIsNotNone(db_test_post)
        self.assertEqual(db_test_post.body_html, '<p>This is a <strong>test</strong> post.</p>')
        self.assertEqual(db_test_post.body_ja_html, '<p>これはテスト書き込みですね。</p>')
        db_cat = db_test_post.category_id
        self.assertIsNotNone(db_cat)
        db_tags = []
        for tag in db_test_post.tags:
            db_tags.append(tag.id)
        self.assertIsNot(len(db_tags), 0)

        db.session.delete(db_test_post)
        db.session.commit()

        # Ensure orphaned categories and tags are deleted
        cat = Category.query.filter(id == db_cat).first()
        self.assertIsNone(cat)

        for tag_id in db_tags:
            tag = Tag.query.filter(id == tag_id).first()
            self.assertIsNone(tag)
Пример #2
0
def create_post():

    # can't make a post without a published date?

    form = PostForm()
    if form.validate_on_submit():

        new_post = Post(form.title.data, form.slug.data)

        new_post.add_category(form.category.data, form.category_ja.data)
        new_post.add_tags(form.tags.data, form.tags_ja.data)
        new_post.add_body(form.body.data, form.body_ja.data)

        if new_post.published:
            published_date = form.date.data - timedelta(hours=new_post.get_tz_offset())
            new_post.date = published_date
        new_post.title_ja = form.title_ja.data

        db.session.add(new_post)
        db.session.commit()

        return redirect(url_for('posts.post_item', slug=form.slug.data))
    return render_template('post_create.html',
                           form=form)
Пример #3
0
def create_test_posts():
    p1 = Post("Test Post", "test_post")
    p1.add_category("Testing", "テスト中")
    p1.add_tags("test;experiment", "テスト;実験")
    p1.add_body("This is a test post.", "これはテストの書き込みです。")
    p1.published = True
    p1.date = datetime.now() - timedelta(hours=p1.get_tz_offset())
    db.session.add(p1)
    db.session.commit()
    p2 = Post("Another Test Post", "another_test_post")
    p2.add_category("Testing Another")
    p2.add_tags("test;experiment")
    p2.add_body("This is another test post.")
    db.session.add(p2)
    db.session.commit()