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",
--- /dev/null
+<%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
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
--- /dev/null
+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}