From 30144dddc6bb6f44bbe771394f36189324ca9eb6 Mon Sep 17 00:00:00 2001 From: Jan Behrens Date: Wed, 17 Apr 2013 09:10:53 +0200 Subject: [PATCH] Adding gametype-filtered game_index view (and fix bug in player_game_index) Not linked anywhere yet, but can be accessed via .../player/###/games/gametype --- xonstat/__init__.py | 5 +++++ xonstat/templates/player_game_index.mako | 4 ++++ xonstat/views/helpers.py | 6 +++++- xonstat/views/player.py | 15 +++++++++++---- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/xonstat/__init__.py b/xonstat/__init__.py index 08946ad..ee594ad 100644 --- a/xonstat/__init__.py +++ b/xonstat/__init__.py @@ -41,6 +41,11 @@ def main(global_config, **settings): config.add_view(player_game_index, route_name="player_game_index", renderer="player_game_index.mako") config.add_view(player_game_index_json, route_name="player_game_index_json", renderer="jsonp") + config.add_route("player_game_index_filtered", "/player/{player_id:\d+}/games/{game_type_cd:\w+}") + config.add_route("player_game_index_filtered_json", "/player/{player_id:\d+}/games/{game_type_cd:\w+}.json") + config.add_view(player_game_index, route_name="player_game_index_filtered", renderer="player_game_index.mako") + config.add_view(player_game_index_json, route_name="player_game_index_filtered_json", renderer="jsonp") + config.add_route("player_info", "/player/{id:\d+}") config.add_route("player_info_json", "/player/{id:\d+}.json") config.add_view(player_info, route_name="player_info", renderer="player_info.mako") diff --git a/xonstat/templates/player_game_index.mako b/xonstat/templates/player_game_index.mako index 1953cb2..77535fe 100644 --- a/xonstat/templates/player_game_index.mako +++ b/xonstat/templates/player_game_index.mako @@ -17,7 +17,11 @@ Recent Games % else:
+ % if not game_type_cd:

Recent Games by ${player.nick_html_colors()|n}

+ % else: +

Recent ${game_type_cd.upper()} Games by ${player.nick_html_colors()|n}

+ % endif

Back to player info page

diff --git a/xonstat/views/helpers.py b/xonstat/views/helpers.py index cbaed24..2f2db70 100644 --- a/xonstat/views/helpers.py +++ b/xonstat/views/helpers.py @@ -75,7 +75,7 @@ class RecentGame(object): return "" % (self.game_id, self.game_type_cd, self.server_name, self.map_name) -def recent_games_q(server_id=None, map_id=None, player_id=None, cutoff=None): +def recent_games_q(server_id=None, map_id=None, player_id=None, game_type_cd=None, cutoff=None): ''' Returns a SQLA query of recent game data. Parameters filter the results returned if they are provided. If not, it is @@ -113,6 +113,10 @@ def recent_games_q(server_id=None, map_id=None, player_id=None, cutoff=None): recent_games_q = recent_games_q.\ filter(PlayerGameStat.rank==1) + if game_type_cd is not None: + recent_games_q = recent_games_q.\ + filter(Game.game_type_cd==game_type_cd.lower()) + if cutoff is not None: right_now = datetime.utcnow() recent_games_q = recent_games_q.\ diff --git a/xonstat/views/player.py b/xonstat/views/player.py index a183114..c037901 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -596,6 +596,10 @@ def player_info_json(request): def player_game_index_data(request): player_id = request.matchdict['player_id'] + try: + game_type_cd = request.matchdict['game_type_cd'] + except: + game_type_cd = None if request.params.has_key('page'): current_page = request.params['page'] @@ -603,10 +607,12 @@ def player_game_index_data(request): current_page = 1 try: - player = DBSession.query(Player).filter_by(player_id=player_id).\ - filter(Player.active_ind == True).one() + player = DBSession.query(Player).\ + filter_by(player_id=player_id).\ + filter(Player.active_ind == True).\ + one() - rgs_q = recent_games_q(player_id=player.player_id) + rgs_q = recent_games_q(player_id=player.player_id, game_type_cd=game_type_cd) games = Page(rgs_q, current_page, items_per_page=10, url=page_url) @@ -619,8 +625,10 @@ def player_game_index_data(request): return { 'player_id':player.player_id, + 'player_url':request.route_url('player_info', id=player_id), 'player':player, 'games':games, + 'game_type_cd':game_type_cd, } @@ -641,7 +649,6 @@ 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'] -- 2.39.2