def _view_game(game_id, init_path, game_edit_form=None, comment_form=None): """ Views existing game on given (comment) path. When there are errors with comment for instance of this one can be passed in and errors displayed. """ game = db.get_game(game_id) if not game: abort(404) # fetch games owner db.annotate(game) comments=list(db.get_comments_for_game(game_id)) for comment in comments: db.annotate(comment) # forms if not comment_form: comment_form = forms.CommentForm() user = db.get_user_by_username(session.get("username", None)) typeahead_players = [] if user and game.is_owner(user) and not game_edit_form: game_edit_form = forms.GameEditForm.form_factory(game.type)() # hint for inputting players names typeahead_players = dict([(player.name, player.rank) for player in db.get_players()]) print game.nodes return render_template("view_game.html", game=game, init_path=init_path, comments=comments, comment_paths=[(str(c["_id"]), c["path"]) for c in comments], comment_form=comment_form, typeahead_players=typeahead_players, game_edit_form=game_edit_form)
def view_sgf(game_id): """Views sgf for game identified by game_id""" game = db.get_game(game_id) if not game: abort(404) annotated_comments = [db.annotate(c) for c in db.get_comments_for_game(game_id)] # this changes the game itself # but that is fine since we don't intend to save it game = db.patch_game_with_comments(game, annotated_comments) response = make_response(sgf.makeSgf([game.export()])) response.headers["Content-type"] = "text/plain" return response