示例#1
0
文件: post.py 项目: pieterdp/helptux
def v_post_delete(post_id):
    a_post = PostApi()
    form = PostDeleteForm()
    try:
        existing_post = a_post.read(post_id)
    except DatabaseItemDoesNotExist as e:
        flash('No post with id {0}'.format(post_id))
        return redirect(url_for('.v_post_list'))
    except Exception as e:
        flash('An unexpected error occurred: {0}'.format(e))
        # flash('An unexpected error occurred.')
        return redirect(url_for('.v_post_list'))

    if request.method == 'POST' and form.validate_on_submit():
        if a_post.delete(post_id) is True:
            flash('Post {0} deleted'.format(existing_post.id))
            return redirect(url_for('.v_post_list'))
        else:
            flash('Unable to delete post {0}'.format(existing_post.id))
            return render_template('admin/post/delete.html',
                                   form=form,
                                   post_id=post_id,
                                   slug=existing_post.slug)

    return render_template('admin/post/delete.html',
                           form=form,
                           post_id=post_id,
                           slug=existing_post.slug)
示例#2
0
文件: post.py 项目: pieterdp/helptux
def v_post_delete(post_id):
    a_post = PostApi()
    form = PostDeleteForm()
    try:
        existing_post = a_post.read(post_id)
    except DatabaseItemDoesNotExist as e:
        flash('No post with id {0}'.format(post_id))
        return redirect(url_for('.v_post_list'))
    except Exception as e:
        flash('An unexpected error occurred: {0}'.format(e))
        # flash('An unexpected error occurred.')
        return redirect(url_for('.v_post_list'))

    if request.method == 'POST' and form.validate_on_submit():
        if a_post.delete(post_id) is True:
            flash('Post {0} deleted'.format(existing_post.id))
            return redirect(url_for('.v_post_list'))
        else:
            flash('Unable to delete post {0}'.format(existing_post.id))
            return render_template('admin/post/delete.html', form=form, post_id=post_id, slug=existing_post.slug)

    return render_template('admin/post/delete.html', form=form, post_id=post_id, slug=existing_post.slug)