Example #1
0
def edit_post(slug):
    post = Post.query.filter_by(slug=slug).first_or_404()
    form = PostForm(obj=post)
    if form.validate_on_submit():
        # Still if you change the ja category or tag (as in add a translation),
        # the below won't update it
        post.add_category(form.category.data, form.category_ja.data)
        post.add_tags(form.tags.data, form.tags_ja.data)
        post.add_body(form.body.data, form.body_ja.data)

        post.title = form.title.data
        post.title_ja = form.title_ja.data
        post.slug = form.slug.data
        post.published = form.published.data
        if post.published:
            published_date = form.date.data - timedelta(hours=post.get_tz_offset())
            post.date = published_date
        db.session.commit()

        return redirect(url_for('posts.post_item', slug=form.slug.data))

    return render_template('post_create.html',
                           form=form)
Example #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)