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 recent(u): char = request.args.get("char", None) if char is not None: if char == "anything-goes": # Get all characters that exist in this universe who have had any # appearances. This could fail, in which case we bail with a cute # error message. q = Character.query.filter_by(universe=u) chars = q.filter(Character.comics.any()).all() if not chars: flash("No characters have been introduced yet. Patience, " "grasshopper.") return redirect(url_for("recent", u=u)) char = choice(chars) else: char = Character.query.filter_by(universe=u, slug=char).first() if not char: flash("That character doesn't exist. I'm sorry, but we don't " "have fanfiction-based characters in the story.") return redirect(url_for("recent", u=u)) elif not char.comics: flash("That character has not made an appearance yet. We " "know how popular they are, though, so be prepared for " "their debut!") return redirect(url_for("recent", u=u)) q = get_comic_query(u) if char: q = q.filter(Comic.characters.contains(char)) comic = q.order_by(Comic.id.desc()).first() if not comic: # We probably shouldn't have been able to get here, in general. This # could happen if there are no comics in this universe yet. However, # it could possibly happen if there is some bug in the above # character-sorting logic. Be aware of this when debugging this code # later. :3 flash("No comics could be found. Something went wrong, perhaps?") return redirect(url_for("index")) if char: return redirect(url_for_comic(comic, char=char.slug)) else: return redirect(url_for_comic(comic))
def universe_rss(u): q = get_comic_query(u).order_by(Comic.time.desc()) comics = q[:10] stuff = [] for comic in comics: url = url_for_comic(comic, _external=True) stuff.append((url, comic)) link = url_for("recent", _external=True, u=u) return make_rss2(link, u.title, stuff)
def rss(): # Filter out comics that have not yet gone live. q = Comic.query.filter(Comic.time < datetime.now()) comics = q.order_by(Comic.time.desc())[:10] stuff = [] for comic in comics: url = url_for_comic(comic, _external=True) stuff.append((url, comic)) link = url_for("index", _external=True) return make_rss2(link, "DCoN", stuff)