コード例 #1
0
ファイル: posts.py プロジェクト: mtrom/ambassador
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']))
コード例 #2
0
ファイル: posts.py プロジェクト: mtrom/ambassador
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())
コード例 #3
0
ファイル: posts.py プロジェクト: mtrom/ambassador
def add_post():
    if request.method == 'GET':
        return render_template('forms/add_post.html', post=None)

    form = request.form.copy()

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

    form['thumbnail'] = request.files['thumbnail']
    form['image']     = request.files['image']

    Post.add(form)
    send("*****@*****.**", "*****@*****.**", \
            "New Ambassador Post", form['title'])

    return redirect(url_for('blog'))
コード例 #4
0
ファイル: posts.py プロジェクト: mtrom/ambassador
def delete_post():
    post = Post.get(request.args.get('ID'))
    post.delete()
    return redirect(url_for('admin'))