From f1fda75b8d674d547fda366624790c1ca7ab233a Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Thu, 18 Apr 2013 20:51:20 -0400 Subject: [PATCH] Fix broken things in game_index. - New routes defined when not needed (see previous commit). - Query params persisted via search_query. - Inline if statement to show game type description. --- xonstat/__init__.py | 5 ----- xonstat/templates/game_index.mako | 20 +++++++++--------- xonstat/views/game.py | 35 +++++++++++++++++++------------ 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/xonstat/__init__.py b/xonstat/__init__.py index 6f3b9d6..08946ad 100644 --- a/xonstat/__init__.py +++ b/xonstat/__init__.py @@ -79,11 +79,6 @@ 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 da6205d..dda3ce1 100644 --- a/xonstat/templates/game_index.mako +++ b/xonstat/templates/game_index.mako @@ -17,20 +17,20 @@ Game Index % if not games: - % if not game_type_cd: -

Sorry, no games yet. Get playing!

- % else: -

Sorry, no ${game_type_cd.upper()} games yet. Get playing!

+

Sorry, no + % if game_type_descr: + ${game_type_descr} % endif + games yet. Get playing!

% else:
- % if not game_type_cd: -

Recent Games

- % else: -

Recent ${game_type_cd.upper()} Games

+

Recent + % if game_type_descr: + ${game_type_descr} % endif + Games

@@ -42,7 +42,7 @@ Game Index % if gt == 'overall': % else: - + % endif
${gt}
@@ -66,7 +66,7 @@ Game Index
- ${navlinks("game_index", games.page, games.last_page)} + ${navlinks("game_index", games.page, games.last_page, search_query=request.GET)}
% endif diff --git a/xonstat/views/game.py b/xonstat/views/game.py index 1ed1741..d18da8f 100644 --- a/xonstat/views/game.py +++ b/xonstat/views/game.py @@ -13,16 +13,23 @@ 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 + game_type_cd = None + game_type_descr = None + + if request.params.has_key('game_type_cd'): + game_type_cd = request.params['game_type_cd'] + try: + game_type_descr = DBSession.query(GameType.descr).\ + filter(GameType.game_type_cd == game_type_cd).\ + one()[0] + except Exception as e: + game_type_cd = None if request.params.has_key('page'): current_page = request.params['page'] else: current_page = 1 - + try: rgs_q = recent_games_q(game_type_cd=game_type_cd) @@ -30,22 +37,24 @@ def _game_index_data(request): # replace the items in the canned pagination class with more rich ones games.items = [RecentGame(row) for row in games.items] - + pgstats = {} 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() - + except Exception as e: - games = None - pgstats = None - game_type_cd = None + games = None + pgstats = None + game_type_cd = None + game_type_descr = None return {'games':games, 'pgstats':pgstats, 'game_type_cd':game_type_cd, + 'game_type_descr':game_type_descr, } @@ -117,10 +126,10 @@ def _game_info_data(request): pwstats[pgstat.player_game_stat_id] = [] # NOTE adding pgstat to position 6 in order to display nick. - # You have to use a slice [0:5] to pass to the accuracy + # You have to use a slice [0:5] to pass to the accuracy # template - pwstats[pgstat.player_game_stat_id].append((weapon.descr, - weapon.weapon_cd, pwstat.actual, pwstat.max, + pwstats[pgstat.player_game_stat_id].append((weapon.descr, + weapon.weapon_cd, pwstat.actual, pwstat.max, pwstat.hit, pwstat.fired, pgstat)) except Exception as inst: -- 2.39.2