コード例 #1
0
ファイル: comment.py プロジェクト: setomits/mow
def delete_comment():
    comment_id = request.form.get('comment_id', '').strip()

    if comment_id and comment_id.isdigit():
        comment = Comment.get_by_id(int(comment_id))
        if comment:
            comment.delete()
            return redirect(url_for('admin_top_page'))
        else:
            return abort(404)
    else:
        return abort(400)
コード例 #2
0
ファイル: comment.py プロジェクト: setomits/mow
def comment_editing_page():
    g.active = {'comment': True}

    if request.method == 'GET':
        comment_id = request.args.get('comment_id', '').strip()
    else:
        comment_id = request.form.get('comment_id', '').strip()

    comment = Comment.get_by_id(int(comment_id)) if comment_id.isdigit() else None

    if request.method == 'POST':
        if comment is None:
            return abort(400)

        author_name = request.form.get('author_name', '').strip()
        title = request.form.get('title', '').strip()
        body = request.form.get('body', '').strip()

        to_save = False

        if author_name != comment.author_name:
            comment.author_name = author_name
            to_save = True

        if title != comment.title:
            comment.title = title
            to_save = True

        if body != comment.body:
            comment.body = body
            to_save = True

        if to_save:
            comment.save()

    g.comment = comment

    return render_template('admin/edit_comment_page.html')