コード例 #1
0
ファイル: views.py プロジェクト: jameysharp/dcon
def comment(u, cid):
    if current_user.is_anonymous():
        abort(403)

    try:
        comic = get_comic_query(u).filter_by(id=cid).one()
    except NoResultFound:
        abort(404)

    form = CommentForm()

    if form.validate_on_submit():
        if form.anonymous.data:
            name = "Anonymous"
        else:
            name = current_user.username

        post = Post(name, form.comment.data, "", None)
        post.thread = comic.thread

        image = form.datafile.file
        if image:
            post.filename = chan_filename(image)
            save_file(post.fp(), image)

        db.session.add(post)
        db.session.commit()

    return redirect(url_for_comic(comic))