From: Ant Zucaro Date: Sat, 16 Jan 2016 13:00:58 +0000 (-0500) Subject: Throw HTTP 404s if either the player or map do not exist. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2f2721d2def98b4322e694fab64f95d1ce1e8b6a;p=xonotic%2Fxonstat.git Throw HTTP 404s if either the player or map do not exist. --- diff --git a/xonstat/views/map.py b/xonstat/views/map.py index 57665e3..a10073d 100644 --- a/xonstat/views/map.py +++ b/xonstat/views/map.py @@ -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) diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 59fcd68..a751ace 100644 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -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)