From: Jan Behrens Date: Wed, 17 Apr 2013 16:29:30 +0000 (+0200) Subject: Added gametype-filtered view to game_index (and updated to use recent_games_q) X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a80dc815bcec4089a1fef28dc49bc3dc3ed4ff0b;p=xonotic%2Fxonstat.git Added gametype-filtered view to game_index (and updated to use recent_games_q) --- diff --git a/xonstat/__init__.py b/xonstat/__init__.py index ee594ad..474c162 100644 --- a/xonstat/__init__.py +++ b/xonstat/__init__.py @@ -84,6 +84,11 @@ def main(global_config, **settings): config.add_view(game_index, route_name="game_index", renderer="game_index.mako") config.add_view(game_index_json, route_name="game_index_json", renderer="jsonp") + config.add_route("game_index_filtered", "/games/{game_type_cd:\w+}") + config.add_route("game_index_filtered_json", "/games/{game_type_cd:\w+}.json") + config.add_view(game_index, route_name="game_index_filtered", renderer="game_index.mako") + config.add_view(game_index_json, route_name="game_index_filtered_json", renderer="jsonp") + config.add_route("game_info", "/game/{id:\d+}") config.add_route("game_info_json", "/game/{id:\d+}.json") config.add_view(game_info, route_name="game_info", renderer="game_info.mako") diff --git a/xonstat/templates/game_index.mako b/xonstat/templates/game_index.mako index a0c0059..cf29f55 100644 --- a/xonstat/templates/game_index.mako +++ b/xonstat/templates/game_index.mako @@ -17,13 +17,17 @@ Game Index % else:
+ % if not game_type_cd:

Recent Games

- % for (game, server, map, gametype) in games: + % else: +

Recent ${game_type_cd.upper()} Games

+ % endif + % for rg in games.items:
- ${game.game_type_cd} -

${map.name} on ${server.name} (permalink)

+ ${rg.game_type_cd} +

${rg.map_name} on ${rg.server_name} (permalink)

- ${scoreboard(game.game_type_cd, pgstats[game.game_id])} + ${scoreboard(rg.game_type_cd, pgstats[rg.game_id])}
% endfor
diff --git a/xonstat/templates/player_game_index.mako b/xonstat/templates/player_game_index.mako index 77535fe..c642568 100644 --- a/xonstat/templates/player_game_index.mako +++ b/xonstat/templates/player_game_index.mako @@ -44,8 +44,8 @@ Recent Games view ${rg.game_type_cd} - ${rg.server_name} - ${rg.map_name} + ${rg.server_name} + ${rg.map_name} % if rg.team != None: % if rg.team == rg.winner: diff --git a/xonstat/views/game.py b/xonstat/views/game.py index 822604f..3d3d44b 100644 --- a/xonstat/views/game.py +++ b/xonstat/views/game.py @@ -13,28 +13,33 @@ log = logging.getLogger(__name__) def _game_index_data(request): + if request.matchdict.has_key('game_type_cd'): + game_type_cd = request.matchdict['game_type_cd'] + else: + game_type_cd = None + if request.params.has_key('page'): current_page = request.params['page'] else: current_page = 1 + + rgs_q = recent_games_q(game_type_cd=game_type_cd) - games_q = DBSession.query(Game, Server, Map, GameType).\ - filter(Game.server_id == Server.server_id).\ - filter(Game.map_id == Map.map_id).\ - filter(Game.game_type_cd == GameType.game_type_cd).\ - order_by(Game.game_id.desc()) - - games = Page(games_q, current_page, items_per_page=10, url=page_url) + games = Page(rgs_q, current_page, items_per_page=10, url=page_url) + # replace the items in the canned pagination class with more rich ones + games.items = [RecentGame(row) for row in games.items] + pgstats = {} - for (game, server, map, gametype) in games: + for game in games.items: pgstats[game.game_id] = DBSession.query(PlayerGameStat).\ filter(PlayerGameStat.game_id == game.game_id).\ order_by(PlayerGameStat.scoreboardpos).\ order_by(PlayerGameStat.score).all() return {'games':games, - 'pgstats':pgstats} + 'pgstats':pgstats, + 'game_type_cd':game_type_cd} def game_index(request): diff --git a/xonstat/views/player.py b/xonstat/views/player.py index c037901..5f0fdef 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -596,9 +596,9 @@ def player_info_json(request): def player_game_index_data(request): player_id = request.matchdict['player_id'] - try: + if request.matchdict.has_key('game_type_cd'): game_type_cd = request.matchdict['game_type_cd'] - except: + else: game_type_cd = None if request.params.has_key('page'): @@ -649,6 +649,7 @@ def player_game_index_json(request): """ return [{'status':'not implemented'}] + def player_accuracy_data(request): player_id = request.matchdict['id'] allowed_weapons = ['nex', 'rifle', 'shotgun', 'uzi', 'minstanex']