]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Added gametype-filtered view to game_index (and updated to use recent_games_q)
authorJan Behrens <zykure@web.de>
Wed, 17 Apr 2013 16:29:30 +0000 (18:29 +0200)
committerJan Behrens <zykure@web.de>
Wed, 17 Apr 2013 16:29:30 +0000 (18:29 +0200)
xonstat/__init__.py
xonstat/templates/game_index.mako
xonstat/templates/player_game_index.mako
xonstat/views/game.py
xonstat/views/player.py

index ee594adbd81f6a3cae16412fda479c3eb99f9c5d..474c162553bddd206eb1b231dddf117893c8d345 100644 (file)
@@ -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")
index a0c0059831161959b559cfd5fd73271bd693acc5..cf29f555cd9ffa7d488d485ea76a38e4efb8924c 100644 (file)
@@ -17,13 +17,17 @@ Game Index
 % else:
 <div class="row">
   <div class="span10 offset1">
+    % if not game_type_cd:
     <h2>Recent Games</h2>
-    % for (game, server, map, gametype) in games:
+    % else:
+    <h2>Recent ${game_type_cd.upper()} Games</h2>
+    % endif
+    % for rg in games.items:
     <div class="game">
-      <img src="/static/images/icons/48x48/${game.game_type_cd}.png" width="30" height="30" alt="${game.game_type_cd}" title="${gametype.descr}"/>
-      <h4><a href="${request.route_url("map_info", id=map.map_id)}" name="Map info page for ${map.name}">${map.name}</a> on <a href="${request.route_url("server_info", id=server.server_id)}" name="Server info page for ${server.name}">${server.name}</a> <span class="permalink">(<a href="${request.route_url('game_info', id=game.game_id)}" name="Permalink for game #${game.game_id}">permalink</a>)</span></h4>
+      <img src="/static/images/icons/48x48/${rg.game_type_cd}.png" width="30" height="30" alt="${rg.game_type_cd}" title="${rg.game_type_descr}"/>
+      <h4><a href="${request.route_url("map_info", id=rg.map_id)}" name="Map info page for ${rg.map_name}">${rg.map_name}</a> on <a href="${request.route_url("server_info", id=rg.server_id)}" name="Server info page for ${rg.server_name}">${rg.server_name}</a> <span class="permalink">(<a href="${request.route_url('game_info', id=rg.game_id)}" name="Permalink for game #${rg.game_id}">permalink</a>)</span></h4>
       <span class="clear"></span>
-      ${scoreboard(game.game_type_cd, pgstats[game.game_id])}
+      ${scoreboard(rg.game_type_cd, pgstats[rg.game_id])}
     </div>
     % endfor
   </div>
index 77535fe1746e0fa4286f31a3d2c156a489263925..c642568f254e1f35faf277b917850edfb380fcc4 100644 (file)
@@ -44,8 +44,8 @@ Recent Games
       <tr>
         <td class="tdcenter"><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=rg.game_id)}" title="View detailed information about this game">view</a></td>
         <td class="tdcenter"><img title="${rg.game_type_cd}" src="/static/images/icons/24x24/${rg.game_type_cd}.png" alt="${rg.game_type_cd}" /></td>
-        <td>${rg.server_name}</td>
-        <td>${rg.map_name}</td>
+        <td><a href="${request.route_url("server_info", id=rg.server_id)}" name="Server info page for ${rg.server_name}">${rg.server_name}</a></td>
+        <td><a href="${request.route_url("map_info", id=rg.map_id)}" name="Map info page for ${rg.map_name}">${rg.map_name}</a></td>
         <td>
           % if rg.team != None:
           % if rg.team == rg.winner:
index 822604f7f93003b29675dd8404d3cd64bd9ae557..3d3d44b0fcc8a1743e81bae39662cf001d8f8752 100644 (file)
@@ -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):
index c0379017be4f2738c8fc665e7ac04ea9bf9bab14..5f0fdef4ccd7543e51361584fee2be5373bf0170 100644 (file)
@@ -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']