]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Add another sorting option to player_captimes.
authorAnt Zucaro <azucaro@gmail.com>
Wed, 27 Jan 2016 01:10:28 +0000 (20:10 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Wed, 27 Jan 2016 01:10:28 +0000 (20:10 -0500)
You can now sort by two fields: most recent and fastest. This is done with a
line at the bottom of the table that allows you to toggle. Fixes #163.

xonstat/templates/player_captimes.mako
xonstat/views/player.py

index afe2828fcaa4c9120fb04d0f19dd84edffff5b7a..8391fb5312c511d92f274eb443799d575790a9ec 100644 (file)
 
   <div class="row">
     <div class="small-12 columns">
-      <h5>Fastest Flag Captures by
+      <h4>Fastest Flag Captures by
         <a href="${request.route_url('player_info', id=player.player_id)}">
           ${player.nick_html_colors()|n}
         </a>
-      </h5>
+      </h4>
+
    
       <table class="table-hover table-condensed">
         <thead>
         </tbody>
       </table>
 
+      % if sort == "fastest":
+          <p>* sorted by fastest - sort by <a href="${request.route_url('player_captimes', player_id=player.player_id, _query={"sort":"create_dt", "page":page})}">most recent</a> instead</p>
+      % else:
+          <p>* sorted by most recent - sort by <a href="${request.route_url('player_captimes', player_id=player.player_id, _query={"sort":"fastest", "page":page})}">fastest</a> instead</p>
+      % endif
+
     </div>
   </div>
 
index faabcba3159bfe9ae26b527a3b766b85da74867a..439f19dbf4f5304ef4c206c12ad7556fa4301115 100644 (file)
@@ -976,7 +976,9 @@ def player_captimes_data(request):
     if player_id <= 2:
         player_id = -1;
 
-    current_page = request.params.get("page", 1)
+    page = request.params.get("page", 1)
+
+    sort = request.params.get("sort", "create_dt")
 
     try:
         player = DBSession.query(Player).filter_by(player_id=player_id).one()
@@ -987,13 +989,18 @@ def player_captimes_data(request):
                 filter(PlayerCaptime.player_id==player_id).\
                 filter(PlayerCaptime.game_id==Game.game_id).\
                 filter(PlayerCaptime.map_id==Map.map_id).\
-                filter(Game.server_id==Server.server_id).\
-                order_by(expr.desc(PlayerCaptime.create_dt))
+                filter(Game.server_id==Server.server_id)
+
+        if sort == "fastest":
+            pct_q = pct_q.order_by(PlayerCaptime.fastest_cap)
+        else:
+            sort = "create_dt"
+            pct_q = pct_q.order_by(expr.desc(PlayerCaptime.create_dt))
 
     except Exception as e:
         raise pyramid.httpexceptions.HTTPNotFound
 
-    captimes = Page(pct_q, current_page, items_per_page=20, url=page_url)
+    captimes = Page(pct_q, page, items_per_page=20, url=page_url)
 
     # replace the items in the canned pagination class with more rich ones
     captimes.items = [PlayerCapTime(row) for row in captimes.items]
@@ -1002,6 +1009,8 @@ def player_captimes_data(request):
             "player_id" : player_id,
             "player"    : player,
             "captimes"  : captimes,
+            "page"      : page,
+            "sort"      : sort,
         }