示例#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)
示例#3
0
文件: post.py 项目: pieterdp/helptux
def v_post_list():
    a_post = PostApi()
    l_posts = a_post.list()
    return render_template('admin/post/list.html', posts=l_posts)
示例#4
0
文件: post.py 项目: pieterdp/helptux
def v_post_list():
    a_post = PostApi()
    l_posts = a_post.list()
    return render_template('admin/post/list.html', posts=l_posts)
示例#5
0
from flask import render_template, redirect, url_for, abort, flash
from helptux.views.blog.viewer import ViewPost
from helptux.modules.api.post import PostApi
from helptux.modules.error import DatabaseItemDoesNotExist
from helptux import app

a_post = PostApi()
v_post = ViewPost()


@app.route('/blog/post/<int:post_id>')
@app.route('/blog/<int:post_id>')
@app.route('/blog/post/<string:post_slug>')
@app.route('/blog/<string:post_slug>')  # Strings are default, get them last (ints are also strings)
def v_show_post(post_id=None, post_slug=None):
    # Get the existing post
    try:
        if post_id:
            post = a_post.read(post_id)
        elif post_slug:
            post = a_post.by_slug(post_slug)
        else:
            raise DatabaseItemDoesNotExist
    except DatabaseItemDoesNotExist as e:
        # Do a 404
        abort(404)
        return ''
    if post.is_deleted:
        abort(404)
        return ''
    if not post.is_visible: