]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Fix the broken things in player_game_index.
authorAnt Zucaro <azucaro@gmail.com>
Fri, 19 Apr 2013 00:30:55 +0000 (20:30 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Fri, 19 Apr 2013 00:30:55 +0000 (20:30 -0400)
- New routes were defined (/player/:id/game_type_cd) when a query
  parameter is the better fit. Game types are a filter condition
  on the resource, not the resource itself, thus should not be in
  the route.

- Pagination was broken. Passing search_query to route_url makes
  the query parameters persist, although I pass query parameters
  in an awful way that needs to be fixed.

- Multiple lines just to show the game type description when an if
  statement would do the same thing.

- No need to pass the player_url to the template. You can reverse-
  generate URLs to routes with route_url just fine.

- Remove the extra link back to the player_info page, as the
  pattern throughout the rest of the application is to click the
  nick itself.

xonstat/__init__.py
xonstat/templates/player_game_index.mako
xonstat/views/player.py

index 474c162553bddd206eb1b231dddf117893c8d345..6f3b9d6498e713966acdaa7752fa51a990b1480b 100644 (file)
@@ -41,11 +41,6 @@ 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")
index c2fd6cee737020434f2b1d9b93f00b69636d8646..f02a6b3e1b4f7687d386418c79200f5f1f709f48 100644 (file)
@@ -16,25 +16,30 @@ Recent Games
 </%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>
-  % endif
+<h2>Sorry, no 
+    % if game_type_descr:
+    ${game_type_descr}
+    % endif
+  games yet for 
+  <a href="${request.route_url('player_info', id=player.player_id)}">${player.nick_html_colors()|n}</a>. Get playing!
+</h2>
 <p><a href="${player_url}">Back to player info page</a></p>
 
 % else:
 <div class="row">
   <div class="span12">
-    % if not game_type_cd:
-    <h3>Recent Games by ${player.nick_html_colors()|n}</h3>
-    % else:
-    <h3>Recent ${game_type_cd.upper()} Games by ${player.nick_html_colors()|n}</h3>
-    % endif
-    <p><a href="${player_url}">Back to player info page</a></p>
+    <h3>Recent 
+      % if game_type_descr:
+      ${game_type_descr}
+      % endif
+      Games by 
+      <a href="${request.route_url('player_info', id=player.player_id)}">
+        ${player.nick_html_colors()|n}
+      </a>
+    </h3>
   </div>
 </div>
-<br/>
+
 <div class="row">
   <div class="span12 tabbable">
     <ul class="nav nav-tabs">
@@ -43,7 +48,7 @@ Recent Games
       % if game.game_type_cd == 'overall':
       <a href="${request.route_url("player_game_index", player_id=player.player_id)}" alt="${game.game_type_cd}" title="" data-toggle="none">
       % else:
-      <a href="${request.route_url("player_game_index_filtered", player_id=player.player_id, game_type_cd=game.game_type_cd)}" alt="${game.game_type_cd}" title="" data-toggle="none">
+      <a href="${request.route_url("player_game_index", player_id=player.player_id, _query={'game_type_cd':game.game_type_cd})}" alt="${game.game_type_cd}" title="" data-toggle="none">
       % endif
         <span class="sprite sprite-${game.game_type_cd}"> </span><br />
         ${game.game_type_cd} <br />
@@ -92,14 +97,14 @@ Recent Games
           <a href="${request.route_url('game_info', id=rg.game_id, _query={'show_elo':1})}" title="View detailed information about this game">
             % if rg.elo_delta is not None:
             % if round(rg.elo_delta,2) > 0:
-            <span title="Elo went up by ${round(rg.elo_delta,2)}"><i class="glyphicon glyphicon-arrow-up"></i></span>
+            <span class="eloup" title="Elo went up by ${round(rg.elo_delta,2)}"><i class="glyphicon glyphicon-arrow-up"></i></span>
             % elif round(rg.elo_delta,2) < 0:
-            <span title="Elo went down by ${round(-rg.elo_delta,2)}"><i class="glyphicon glyphicon-arrow-down"></i></span>
+            <span class="elodown" title="Elo went down by ${round(-rg.elo_delta,2)}"><i class="glyphicon glyphicon-arrow-down"></i></span>
             % else:
-            <span title="Elo did not change"><i class="glyphicon glyphicon-minus"></i></span>
+            <span class="eloneutral" title="Elo did not change"><i class="glyphicon glyphicon-minus"></i></span>
             % endif
             % else:
-            <span title="Elo did not change"><i class="glyphicon glyphicon-minus"></i></span>
+            <span class="eloneutral" title="Elo did not change"><i class="glyphicon glyphicon-minus"></i></span>
             % endif
           </a>
         </td>
@@ -112,5 +117,5 @@ Recent Games
 
 
 <!-- navigation links -->
-${navlinks("player_game_index", games.page, games.last_page, player_id=player_id)}
+${navlinks("player_game_index", games.page, games.last_page, player_id=player_id, search_query=request.GET)}
 % endif
index 952946055ba049c78362949cc16c79ae84158891..94fe8cb613d0bec6bce2cc3069f80933fbab90e3 100644 (file)
@@ -596,10 +596,22 @@ def player_info_json(request):
 
 def player_game_index_data(request):
     player_id = request.matchdict['player_id']
-    if request.matchdict.has_key('game_type_cd'):
-        game_type_cd  = request.matchdict['game_type_cd']
+
+    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:
+            pass
+
     else:
-        game_type_cd  = None
+        game_type_cd = None
+        game_type_descr = None
 
     if request.params.has_key('page'):
         current_page = request.params['page']
@@ -618,21 +630,22 @@ def player_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]
-        
+
         games_played = get_games_played(player_id)
 
     except Exception as e:
         player = None
         games = None
         game_type_cd = None
+        game_type_descr = None
         games_played = None
 
     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,
+            'game_type_descr':game_type_descr,
             'games_played':games_played,
            }