コード例 #1
0
ファイル: blog.py プロジェクト: ryankask/esther
def edit_post(post_id):
    post = Post.query.filter_by(author=current_user, id=post_id).first_or_404()
    form = PostForm(request.form, obj=post)

    if form.validate_on_submit():
        form.populate_obj(post)

        if (post.pub_date is None and post.status == PostStatus.published):
            post.pub_date = utc_now()

        db.session.commit()
        message = u'Edited post "{}".'.format(form.title.data)
        flash(message, 'success')
        return redirect(url_for('.view_posts'))

    return render_template('blog/post_edit.html', post=post, form=form)
コード例 #2
0
def edit_post(post_id):
    post = Post.query.filter_by(author=current_user, id=post_id).first_or_404()
    form = PostForm(request.form, obj=post)

    if form.validate_on_submit():
        form.populate_obj(post)

        if (post.pub_date is None and post.status == PostStatus.published):
            post.pub_date = utc_now()

        db.session.commit()
        message = u'Edited post "{}".'.format(form.title.data)
        flash(message, 'success')
        return redirect(url_for('.view_posts'))

    return render_template('blog/post_edit.html', post=post, form=form)
コード例 #3
0
ファイル: blog.py プロジェクト: ryankask/esther
def add_post():
    form = PostForm(request.form)

    if form.validate_on_submit():
        status = PostStatus.from_string(form.status.data)

        post = Post(author=current_user, title=form.title.data,
                    slug=form.slug.data, body=form.body.data,
                    status=status, tags=form.tags.data)

        if status == PostStatus.published:
            post.pub_date = utc_now()

        db.session.add(post)
        db.session.commit()

        message = u'Post "{}" successfully added.'.format(form.title.data)
        flash(message, 'success')
        return redirect(url_for('.view_posts'))

    return render_template('blog/post_add.html', form=form)
コード例 #4
0
def add_post():
    form = PostForm(request.form)

    if form.validate_on_submit():
        status = PostStatus.from_string(form.status.data)

        post = Post(author=current_user,
                    title=form.title.data,
                    slug=form.slug.data,
                    body=form.body.data,
                    status=status,
                    tags=form.tags.data)

        if status == PostStatus.published:
            post.pub_date = utc_now()

        db.session.add(post)
        db.session.commit()

        message = u'Post "{}" successfully added.'.format(form.title.data)
        flash(message, 'success')
        return redirect(url_for('.view_posts'))

    return render_template('blog/post_add.html', form=form)