Start work on main page. Only top players passed right now.
authorAnt Zucaro <azucaro@gmail.com>
Mon, 6 Jun 2011 18:08:27 +0000 (14:08 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Mon, 6 Jun 2011 18:08:27 +0000 (14:08 -0400)
xonstat/__init__.py
xonstat/templates/main_index.mako [new file with mode: 0755]
xonstat/views/__init__.py
xonstat/views/main.py [new file with mode: 0755]

index 2dde41a3231d11b787af6801b4bd0158709d8be7..386fd0a8a49827dd2f4a39888aeff221bdd6fc85 100755 (executable)
@@ -22,8 +22,8 @@ def main(global_config, **settings):
     config.add_static_view('static', 'xonstat:static')
 
     # ROOT ROUTE
-    config.add_route(name="main_index", pattern="/", view=game_index,
-            renderer='game_index.mako') 
+    config.add_route(name="main_index", pattern="/", view=main_index,
+            renderer='main_index.mako') 
 
     # PLAYER ROUTES
     config.add_route(name="player_game_index_default", 
diff --git a/xonstat/templates/main_index.mako b/xonstat/templates/main_index.mako
new file mode 100755 (executable)
index 0000000..0b03aed
--- /dev/null
@@ -0,0 +1,25 @@
+<%inherit file="base.mako"/>\r
+\r
+<%block name="title">\r
+Main Page - ${parent.title()}\r
+</%block>\r
+\r
+<table>\r
+<tr>\r
+<th>Nick</th>\r
+<th>Score</th>\r
+</tr>\r
+% for (player_id, nick, score) in top_players:\r
+<tr>\r
+<td>${nick}</td>\r
+<td>${score}</td>\r
+</tr>\r
+% endfor\r
+\r
+% for i in range(10 - len(top_players)):\r
+<tr>\r
+<td>-</td>\r
+<td>-</td>\r
+</tr>\r
+% endfor\r
+</table>\r
index 62b0be5d396adf79f0e2ba8635c60f6c39d25815..229b7f9f55f9f65d53c32bd1cfbbc641df262021 100755 (executable)
@@ -3,3 +3,4 @@ from xonstat.views.player import player_index, player_info, player_game_index
 from xonstat.views.game import game_index, game_info\r
 from xonstat.views.map import map_info\r
 from xonstat.views.server import server_info, server_game_index\r
+from xonstat.views.main import main_index\r
diff --git a/xonstat/views/main.py b/xonstat/views/main.py
new file mode 100755 (executable)
index 0000000..33f0b3d
--- /dev/null
@@ -0,0 +1,16 @@
+import logging
+import sqlalchemy.sql.functions as func
+from pyramid.response import Response
+from xonstat.models import *
+
+log = logging.getLogger(__name__)
+
+def main_index(request):
+    top_players = DBSession.query(Player.player_id, Player.nick, func.sum(PlayerGameStat.score)).\
+            filter(Player.player_id == PlayerGameStat.player_id).\
+            filter(Player.player_id > 2).\
+            order_by(func.sum(PlayerGameStat.score)).\
+            group_by(Player.nick).\
+            group_by(Player.player_id).all()[0:10]
+
+    return {'top_players':top_players}