]> de.git.xonotic.org Git - xonotic/xonstat.git/blobdiff - xonstat/views/main.py
If there are no recent games, do not show the section.
[xonotic/xonstat.git] / xonstat / views / main.py
index 5a8bad4be70aead377dbf2d384af734b831fb4e1..10505b4a6d54220476a798566cb7a29cf2940de2 100644 (file)
@@ -5,11 +5,14 @@ from datetime import datetime, timedelta
 from pyramid.response import Response
 from xonstat.models import *
 from xonstat.util import *
+from xonstat.views.helpers import RecentGame, recent_games_q
+
 
 log = logging.getLogger(__name__)
 
+
 def _main_index_data(request):
-    try: 
+    try:
         leaderboard_lifetime = int(
                 request.registry.settings['xonstat.leaderboard_lifetime'])
     except:
@@ -83,13 +86,8 @@ def _main_index_data(request):
             group_by(Map.name).limit(leaderboard_count).all()
 
     # recent games played in descending order
-    recent_games = DBSession.query(Game, Server, Map, PlayerGameStat).\
-            filter(Game.server_id==Server.server_id).\
-            filter(Game.map_id==Map.map_id).\
-            filter(PlayerGameStat.game_id==Game.game_id).\
-            filter(PlayerGameStat.rank==1).\
-            filter(expr.between(Game.create_dt, back_then, right_now)).\
-            order_by(expr.desc(Game.start_dt)).limit(recent_games_count).all()
+    rgs = recent_games_q(cutoff=back_then).limit(recent_games_count).all()
+    recent_games = [RecentGame(row) for row in rgs]
 
     return {'top_players':top_players,
             'top_servers':top_servers,
@@ -129,7 +127,11 @@ def main_index(request):
     for i in range(leaderboard_count-len(mainindex_data['top_maps'])):
         mainindex_data['top_maps'].append(('-', '-', '-'))
 
-    for i in range(recent_games_count-len(mainindex_data['recent_games'])):
-        mainindex_data['recent_games'].append(('-', '-', '-', '-'))
-
     return mainindex_data
+
+
+def main_index_json(request):
+    """
+    JSON output of the main page information.
+    """
+    return [{'status':'not implemented'}]