From: Ant Zucaro Date: Wed, 27 Jan 2016 01:10:28 +0000 (-0500) Subject: Add another sorting option to player_captimes. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=add0c904ee8950c43d83cdc1d65228f43b37bede;p=xonotic%2Fxonstat.git Add another sorting option to player_captimes. 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. --- diff --git a/xonstat/templates/player_captimes.mako b/xonstat/templates/player_captimes.mako index afe2828..8391fb5 100644 --- a/xonstat/templates/player_captimes.mako +++ b/xonstat/templates/player_captimes.mako @@ -17,11 +17,12 @@
-
Fastest Flag Captures by +

Fastest Flag Captures by ${player.nick_html_colors()|n} -

+ + @@ -45,6 +46,12 @@
+ % if sort == "fastest": +

* sorted by fastest - sort by most recent instead

+ % else: +

* sorted by most recent - sort by fastest instead

+ % endif +
diff --git a/xonstat/views/player.py b/xonstat/views/player.py index faabcba..439f19d 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -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, }