Beispiel #1
0
def edit_post():
    if request.method == 'GET':
        post = Post.get(request.args.get('ID'))
        return render_template('forms/add_post.html', post=post)

    form = request.form.copy()

    for key in form.keys():
        if len(form[key]) == 0:
            del form[key]

    if request.files['thumbnail'].filename:
        form['thumbnail'] = request.files['thumbnail']

    if request.files['image'].filename:
        form['image'] = request.files['image']

    if form['id'] == form['old_id']:
        del form['old_id']
        post = Post.get(form['id'])
        post.update(form)
    else:
        old = Post.get(form['old_id'])
        del form['old_id']
        form['thumbnail'] = old.thumbnail
        form['image']     = old.image
        old.delete()
        Post.add(form)
    return redirect(url_for('post', ID=form['id']))
Beispiel #2
0
def post():
    post = Post.get(request.args.get('ID'))

    if post is None:
        abort(404)

    return render_template('blog/post.html', post=post.to_dict())
Beispiel #3
0
def delete_post():
    post = Post.get(request.args.get('ID'))
    post.delete()
    return redirect(url_for('admin'))