]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Add a JSON method to the ServerInfo view.
authorAnt Zucaro <azucaro@gmail.com>
Wed, 19 Oct 2016 00:45:04 +0000 (20:45 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Wed, 19 Oct 2016 00:45:04 +0000 (20:45 -0400)
xonstat/views/server.py

index 83d642e6168351a97a88cec151b903b8371e5132..5251b910e9ee74e1179391201f47c4337bf75f17 100644 (file)
@@ -189,7 +189,6 @@ class ServerInfo(ServerInfoBase):
         """Common parameter parsing."""
 
         super(ServerInfo, self).__init__(request)
-        self.server_info = self.raw()
 
     def raw(self):
         """Returns the raw data shared by all renderers."""
@@ -221,8 +220,25 @@ class ServerInfo(ServerInfoBase):
 
     def html(self):
         """For rendering this data using something HTML-based."""
-        return self.server_info
+        return self.raw()
 
     def json(self):
         """For rendering this data using JSON."""
-        return {"status": "Not implemented"}
+        try:
+            server_raw = DBSession.query(Server).filter_by(server_id=self.server_id).one()
+            server = server_raw.to_dict()
+            top_maps = ServerTopMaps(self.request).json()
+            top_scorers = ServerTopScorers(self.request).json()
+            top_players = ServerTopPlayers(self.request).json()
+            rgs = recent_games_q(server_id=self.server_id).limit(RECENT_GAMES_COUNT).all()
+            recent_games = [RecentGame(row).to_dict() for row in rgs]
+        except:
+            raise HTTPNotFound
+
+        return {
+            'server': server,
+            'recent_games': recent_games,
+            'top_players': top_players,
+            'top_scorers': top_scorers,
+            'top_maps': top_maps,
+        }