Add ranks view based on game type.
authorAnt Zucaro <azucaro@gmail.com>
Fri, 20 Jan 2012 01:19:31 +0000 (20:19 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Fri, 20 Jan 2012 01:19:31 +0000 (20:19 -0500)
xonstat/__init__.py
xonstat/templates/rank_index.mako [new file with mode: 0755]
xonstat/views/__init__.py
xonstat/views/game.py

index 7c4593c1e9910b95f5891a532572d5a1a95fd5e9..9eb3599bbf2dd9273e9cf3800b3cc86f180ca354 100755 (executable)
@@ -61,6 +61,14 @@ def main(global_config, **settings):
     config.add_view(game_info, route_name="game_info",
         renderer="game_info.mako")
 
+    config.add_route("rank_index", "/ranks/{game_type_cd:ctf|dm|tdm|duel}")
+    config.add_view(rank_index, route_name="rank_index",
+        renderer="rank_index.mako")
+
+    config.add_route("rank_index_paged", "/ranks/{game_type_cd:ctf|dm|tdm|duel}/page/{page:\d+}")
+    config.add_view(rank_index, route_name="rank_index_paged",
+        renderer="rank_index.mako")
+
     # SERVER ROUTES
     config.add_route("server_index_paged", "/servers/page/{page:\d+}")
     config.add_view(server_index, route_name="server_index_paged",
diff --git a/xonstat/templates/rank_index.mako b/xonstat/templates/rank_index.mako
new file mode 100755 (executable)
index 0000000..3ddb7f9
--- /dev/null
@@ -0,0 +1,43 @@
+<%inherit file="base.mako"/>\r
+<%namespace file="navlinks.mako" import="navlinks" />\r
+\r
+<%block name="title">\r
+Rank Index - ${parent.title()}\r
+</%block>\r
+\r
+% if not ranks:\r
+<h2>Sorry, no ranks yet. Get some buddies together and start playing!</h2>\r
+\r
+% else:\r
+<h2>\r
+% if game_type_cd == 'dm':\r
+Deathmatch \r
+% elif game_type_cd == 'duel':\r
+Duel \r
+% elif game_type_cd == 'tdm':\r
+Team Deathmatch \r
+% elif game_type_cd == 'ctf':\r
+Capture The Flag \r
+% endif\r
+\r
+Rank Index</h2>\r
+<table id="rank-index-table" border="1">\r
+  <tr>\r
+    <th>Rank</th>\r
+    <th>Nick</th>\r
+    <th>Elo</th>\r
+  </tr>\r
+<% i = 1 %>\r
+% for (rank, player) in ranks:\r
+  <tr>\r
+    <td>${i}</td>\r
+    <td><a href="${request.route_url("player_info", id=rank.player_id)}" title="Go to this player's info page">${player.nick_html_colors()|n}</a></th>\r
+    <td>${round(rank.elo, 3)}</th>\r
+  </tr>\r
+<% i += 1 %>\r
+% endfor\r
+</table>\r
+\r
+<!-- navigation links -->\r
+${navlinks("rank_index_paged", ranks.page, ranks.last_page)}\r
+% endif\r
index 9d89e605a32836bed457733a76af9700eecd2faf..87c5e76ed398caa068060a257abf5436de0beda9 100755 (executable)
@@ -1,6 +1,6 @@
 from xonstat.views.submission import stats_submit\r
 from xonstat.views.player import player_index, player_info, player_game_index\r
-from xonstat.views.game import game_index, game_info\r
+from xonstat.views.game import game_index, game_info, rank_index\r
 from xonstat.views.map import map_info, map_index\r
 from xonstat.views.server import server_info, server_game_index, server_index\r
 from xonstat.views.search import *\r
index 370636532f9ba1129783b065eb18eaa046b333a4..25ab4082333742a079b51d56bd91c4741bbe2408 100755 (executable)
@@ -93,3 +93,30 @@ def game_info(request):
             'pgstats':pgstats,\r
             'pwstats':pwstats,\r
             }\r
+\r
+\r
+def rank_index(request):\r
+    """\r
+    Provide a list of gametype ranks, paginated.\r
+    """\r
+    if 'page' in request.matchdict:\r
+        current_page = request.matchdict['page']\r
+    else:\r
+        current_page = 1\r
+\r
+    game_type_cd = request.matchdict['game_type_cd']\r
+\r
+    ranks_q = DBSession.query(PlayerElo, Player).\\r
+            filter(PlayerElo.game_type_cd==game_type_cd).\\r
+            filter(PlayerElo.player_id==Player.player_id).\\r
+            order_by(PlayerElo.elo.desc())\r
+\r
+    ranks = Page(ranks_q, current_page, url=page_url)\r
+\r
+    if len(ranks) == 0:\r
+        ranks = None\r
+\r
+    return {\r
+            'ranks':ranks,\r
+            'game_type_cd':game_type_cd,\r
+           }\r