]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Fix broken things in game_index.
authorAnt Zucaro <azucaro@gmail.com>
Fri, 19 Apr 2013 00:51:20 +0000 (20:51 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Fri, 19 Apr 2013 00:51:20 +0000 (20:51 -0400)
- 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
xonstat/templates/game_index.mako
xonstat/views/game.py

index 6f3b9d6498e713966acdaa7752fa51a990b1480b..08946adb2431b7f7221216ed89dbaeb0f2fc2daf 100644 (file)
@@ -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")
index da6205d56cb9c623bd51a3575599ddc188bf0358..dda3ce14686271dbdb081c8a6486289562cc2362 100644 (file)
@@ -17,20 +17,20 @@ Game Index
 </%block>
 
 % if not games:
-  % if not game_type_cd:
-<h2>Sorry, no games yet. Get playing!</h2>
-  % else:
-<h2>Sorry, no ${game_type_cd.upper()} games yet. Get playing!</h2>
+<h2>Sorry, no 
+  % if game_type_descr:
+  ${game_type_descr}
   % endif
+  games yet. Get playing!</h2>
 
 % else:
 <div class="row">
   <div class="span12">
-    % if not game_type_cd:
-    <h2>Recent Games</h2>
-    % else:
-    <h2>Recent ${game_type_cd.upper()} Games</h2>
+    <h2>Recent 
+    % if game_type_descr:
+    ${game_type_descr}
     % endif
+      Games</h2>
   </div>
 </div>
 <div class="row">
@@ -42,7 +42,7 @@ Game Index
       % if gt == 'overall':
       <a href="${request.route_url("game_index")}" alt="${gt}" title="" data-toggle="none">
       % else:
-      <a href="${request.route_url("game_index_filtered", game_type_cd=gt)}" alt="${gt}" title="" data-toggle="none">
+      <a href="${request.route_url("game_index", _query={'game_type_cd':gt})}" alt="${gt}" title="" data-toggle="none">
       % endif
         <span class="sprite sprite-${gt}"> </span><br />
         ${gt} <br />
@@ -66,7 +66,7 @@ Game Index
 <div class="row">
   <div class="span10 offset1">
     <!-- navigation links -->
-    ${navlinks("game_index", games.page, games.last_page)}
+    ${navlinks("game_index", games.page, games.last_page, search_query=request.GET)}
   </div>
 </div>
 % endif
index 1ed1741f52eb4cbec54bf1ccbceed7f058e9cf85..d18da8f7c3dcea28747ed1f194124b345eae753d 100644 (file)
@@ -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: