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))
def save_file(f): """ Save the given file resource to disk. Returns the filename on disk. """ # Empty file? if not f.content_length: return "" filename = chan_filename(f) f.save("static/images/%s" % filename) return filename