]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Throw HTTP 404s if either the player or map do not exist.
authorAnt Zucaro <azucaro@gmail.com>
Sat, 16 Jan 2016 13:00:58 +0000 (08:00 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Sat, 16 Jan 2016 13:00:58 +0000 (08:00 -0500)
xonstat/views/map.py
xonstat/views/player.py

index 57665e3c426a799f41140ad1f045aa4469bfb48a..a10073d58620d40b3e762f40d3ad7e959c25438e 100644 (file)
@@ -196,19 +196,23 @@ def map_captimes_data(request):
 
     current_page = request.params.get('page', 1)
 
-    mmap = DBSession.query(Map).filter_by(map_id=map_id).one()
-
-    mct_q = DBSession.query(PlayerCaptime.fastest_cap, PlayerCaptime.create_dt,
-            PlayerCaptime.player_id, PlayerCaptime.game_id,
-            Game.server_id, Server.name.label('server_name'),
-            PlayerGameStat.nick.label('player_nick')).\
-            filter(PlayerCaptime.map_id==map_id).\
-            filter(PlayerCaptime.game_id==Game.game_id).\
-            filter(PlayerCaptime.map_id==Map.map_id).\
-            filter(Game.server_id==Server.server_id).\
-            filter(PlayerCaptime.player_id==PlayerGameStat.player_id).\
-            filter(PlayerCaptime.game_id==PlayerGameStat.game_id).\
-            order_by(expr.asc(PlayerCaptime.fastest_cap))
+    try:
+        mmap = DBSession.query(Map).filter_by(map_id=map_id).one()
+
+        mct_q = DBSession.query(PlayerCaptime.fastest_cap, PlayerCaptime.create_dt,
+                PlayerCaptime.player_id, PlayerCaptime.game_id,
+                Game.server_id, Server.name.label('server_name'),
+                PlayerGameStat.nick.label('player_nick')).\
+                filter(PlayerCaptime.map_id==map_id).\
+                filter(PlayerCaptime.game_id==Game.game_id).\
+                filter(PlayerCaptime.map_id==Map.map_id).\
+                filter(Game.server_id==Server.server_id).\
+                filter(PlayerCaptime.player_id==PlayerGameStat.player_id).\
+                filter(PlayerCaptime.game_id==PlayerGameStat.game_id).\
+                order_by(expr.asc(PlayerCaptime.fastest_cap))
+
+    except Exception as e:
+        raise pyramid.httpexceptions.HTTPNotFound
 
     map_captimes = Page(mct_q, current_page, items_per_page=20, url=page_url)
 
index 59fcd68b832e84e090212a9e7abdbfdc533ea220..a751acea4d5ea17f951e78ecb511ed0318753f06 100644 (file)
@@ -1005,16 +1005,20 @@ def player_captimes_data(request):
 
     current_page = request.params.get("page", 1)
 
-    player = DBSession.query(Player).filter_by(player_id=player_id).one()
-
-    pct_q = DBSession.query(PlayerCaptime.fastest_cap, PlayerCaptime.create_dt,
-            PlayerCaptime.player_id, PlayerCaptime.game_id, PlayerCaptime.map_id,
-            Map.name.label('map_name'), Game.server_id, Server.name.label('server_name')).\
-            filter(PlayerCaptime.player_id==player_id).\
-            filter(PlayerCaptime.game_id==Game.game_id).\
-            filter(PlayerCaptime.map_id==Map.map_id).\
-            filter(Game.server_id==Server.server_id).\
-            order_by(expr.desc(PlayerCaptime.create_dt))
+    try:
+        player = DBSession.query(Player).filter_by(player_id=player_id).one()
+
+        pct_q = DBSession.query(PlayerCaptime.fastest_cap, PlayerCaptime.create_dt,
+                PlayerCaptime.player_id, PlayerCaptime.game_id, PlayerCaptime.map_id,
+                Map.name.label('map_name'), Game.server_id, Server.name.label('server_name')).\
+                filter(PlayerCaptime.player_id==player_id).\
+                filter(PlayerCaptime.game_id==Game.game_id).\
+                filter(PlayerCaptime.map_id==Map.map_id).\
+                filter(Game.server_id==Server.server_id).\
+                order_by(expr.desc(PlayerCaptime.create_dt))
+
+    except Exception as e:
+        raise pyramid.httpexceptions.HTTPNotFound
 
     captimes = Page(pct_q, current_page, items_per_page=20, url=page_url)