]> de.git.xonotic.org Git - xonotic/xonstat.git/blobdiff - xonstat/__init__.py
Add separate views for the top servers on a map.
[xonotic/xonstat.git] / xonstat / __init__.py
index 25f4a77c853043e1cb7b022f8619f1992f97e858..f1e3571b8b47413453c03e1586ee9e6c19e22a10 100644 (file)
@@ -1,13 +1,13 @@
 import sqlahelper
 from pyramid_beaker import set_cache_regions_from_settings
-from pyramid.authentication import AuthTktAuthenticationPolicy
-from pyramid.authorization import ACLAuthorizationPolicy
 from pyramid.config import Configurator
 from pyramid.httpexceptions import HTTPNotFound
 from pyramid.renderers import JSONP
 from sqlalchemy import engine_from_config
 from xonstat.models import initialize_db
 from xonstat.views import *
+from xonstat.security import *
+
 
 def main(global_config, **settings):
     """ This function returns a Pyramid WSGI application.
@@ -22,7 +22,7 @@ def main(global_config, **settings):
     # set up beaker cache
     set_cache_regions_from_settings(settings)
 
-    config = Configurator(settings=settings)
+    config = Configurator(settings=settings, root_factory=ACLFactory)
 
     # mako for templating
     config.include('pyramid_mako')
@@ -30,15 +30,13 @@ def main(global_config, **settings):
     # for json-encoded responses
     config.add_renderer('jsonp', JSONP(param_name='callback'))
 
-    # authentication and authorization policies
-    authn_policy = AuthTktAuthenticationPolicy('secret', hashalg='sha512')
-    authz_policy = ACLAuthorizationPolicy()
-    config.set_authentication_policy(authn_policy)
-    config.set_authorization_policy(authz_policy)
-
     # for static assets
     config.add_static_view('static', 'xonstat:static')
 
+    # robots
+    config.add_route("robots", "robots.txt")
+    config.add_view(robots, route_name="robots")
+
     # for 404s
     config.add_view(notfound, context=HTTPNotFound, renderer="404.mako")
 
@@ -48,7 +46,7 @@ def main(global_config, **settings):
 
     # MAIN SUBMISSION ROUTE
     config.add_route("submit_stats", "stats/submit")
-    config.add_view(submit_stats, route_name="submit_stats")
+    config.add_view(submit_stats, route_name="submit_stats", renderer="submit_stats.mako")
 
     # PLAYER ROUTES
     config.add_route("player_game_index",      "/player/{player_id:\d+}/games")
@@ -94,14 +92,17 @@ def main(global_config, **settings):
     config.add_route("player_weaponstats_data_json", "/player/{id:\d+}/weaponstats.json")
     config.add_view(player_weaponstats_data_json, route_name="player_weaponstats_data_json", renderer="jsonp")
 
-    config.add_route("top_players_by_time", "/topactive")
-    config.add_view(top_players_by_time, route_name="top_players_by_time", renderer="top_players_by_time.mako")
+    config.add_route("top_players_index", "/topactive")
+    config.add_view(top_players_index, route_name="top_players_index", renderer="top_players_index.mako")
 
-    config.add_route("top_servers_by_players", "/topservers")
-    config.add_view(top_servers_by_players, route_name="top_servers_by_players", renderer="top_servers_by_players.mako")
+    config.add_route("top_servers_index", "/topservers")
+    config.add_view(top_servers_index, route_name="top_servers_index", renderer="top_servers_index.mako")
 
-    config.add_route("top_maps_by_times_played", "/topmaps")
-    config.add_view(top_maps_by_times_played, route_name="top_maps_by_times_played", renderer="top_maps_by_times_played.mako")
+    config.add_route("top_maps_index", "/topmaps")
+    config.add_view(top_maps_index, route_name="top_maps_index", renderer="top_maps_index.mako")
+
+    config.add_route("player_versus", "/versus")
+    config.add_view(player_versus, route_name="player_versus", renderer="player_versus.mako")
 
     # GAME ROUTES
     config.add_route("game_info",      "/game/{id:\d+}")
@@ -110,40 +111,73 @@ def main(global_config, **settings):
     config.add_route("game_info_json", "/game/{id:\d+}.json")
     config.add_view(game_info_json, route_name="game_info_json", renderer="jsonp")
 
-    config.add_route("rank_index",      "/ranks/{game_type_cd:ctf|dm|tdm|duel|ca|ft}")
+    config.add_route("rank_index", "/ranks/{game_type_cd}")
     config.add_view(rank_index,      route_name="rank_index",      renderer="rank_index.mako")
 
-    config.add_route("rank_index_json", "/ranks/{game_type_cd:ctf|dm|tdm|duel|ca|ft}.json")
+    config.add_route("rank_index_json", "/ranks/{game_type_cd}.json")
     config.add_view(rank_index_json, route_name="rank_index_json", renderer="jsonp")
 
     config.add_route("game_index", "/games")
     config.add_view(game_finder, route_name="game_index", renderer="game_finder.mako")
 
-    # SERVER ROUTES
-    config.add_route("server_index",      "/servers")
-    config.add_view(server_index,      route_name="server_index",      renderer="server_index.mako")
-
-    config.add_route("server_index_json", "/servers.json")
-    config.add_view(server_index_json, route_name="server_index_json", renderer="jsonp")
+    config.add_route("game_index_json", "/games.json")
+    config.add_view(game_finder_json, route_name="game_index_json", renderer="jsonp")
 
-    config.add_route("server_game_index",      "/server/{server_id:\d+}/games/page/{page:\d+}")
-    config.add_view(server_game_index,      route_name="server_game_index",      renderer="server_game_index.mako")
-
-    config.add_route("server_game_index_json", "/server/{server_id:\d+}/games.json")
-    config.add_view(server_game_index_json, route_name="server_game_index_json", renderer="jsonp")
-
-    config.add_route("server_info",      "/server/{id:\d+}")
-    config.add_view(server_info,      route_name="server_info",      renderer="server_info.mako")
-
-    config.add_route("server_info_json", "/server/{id:\d+}.json")
-    config.add_view(server_info_json, route_name="server_info_json", renderer="jsonp")
+    # SERVER ROUTES
+    config.add_route("server_index", "/servers")
+    config.add_view(view=ServerIndex, route_name="server_index", attr="html",
+                    renderer="server_index.mako", accept="text/html")
+    config.add_view(view=ServerIndex, route_name="server_index", attr="json", renderer="json",
+                    accept="application/json")
+
+    config.add_route("server_top_maps", "/server/{id:\d+}/topmaps")
+    config.add_view(view=ServerTopMaps, route_name="server_top_maps", attr="html",
+                    renderer="server_top_maps.mako", accept="text/html")
+    config.add_view(view=ServerTopMaps, route_name="server_top_maps", attr="json", renderer="json",
+                    accept="application/json")
+
+    config.add_route("server_top_active", "/server/{id:\d+}/topactive")
+    config.add_view(view=ServerTopPlayers, route_name="server_top_active", attr="html",
+                    renderer="server_top_active.mako", accept="text/html")
+    config.add_view(view=ServerTopPlayers, route_name="server_top_active", attr="json",
+                    renderer="json", accept="application/json")
+
+    config.add_route("server_top_scorers", "/server/{id:\d+}/topscorers")
+    config.add_view(view=ServerTopScorers, route_name="server_top_scorers", attr="html",
+                    renderer="server_top_scorers.mako", accept="text/html")
+    config.add_view(view=ServerTopScorers, route_name="server_top_scorers", attr="json",
+                    renderer="json", accept="application/json")
+
+    config.add_route("server_info", "/server/{id:\d+}")
+    config.add_view(view=ServerInfo, route_name="server_info", attr="html",
+                    renderer="server_info.mako", accept="text/html")
+    config.add_view(view=ServerInfo, route_name="server_info", attr="json", renderer="json",
+                    accept="application/json")
 
     # MAP ROUTES
-    config.add_route("map_index",      "/maps")
-    config.add_view(map_index,      route_name="map_index",      renderer="map_index.mako")
-
-    config.add_route("map_index_json", "/maps.json")
-    config.add_view(map_index_json, route_name="map_index_json", renderer="jsonp")
+    config.add_route("map_index", "/maps")
+    config.add_view(view=MapIndex, route_name="map_index", attr="html",
+                    renderer="map_index.mako", accept="text/html")
+    config.add_view(view=MapIndex, route_name="map_index", attr="json", renderer="json",
+                    accept="application/json")
+
+    config.add_route("map_top_scorers", "/map/{id:\d+}/topscorers")
+    config.add_view(view=MapTopScorers, route_name="map_top_scorers", attr="html",
+                    renderer="map_top_scorers.mako", accept="text/html")
+    config.add_view(view=MapTopScorers, route_name="map_top_scorers", attr="json",
+                    renderer="json", accept="application/json")
+
+    config.add_route("map_top_active", "/map/{id:\d+}/topactive")
+    config.add_view(view=MapTopPlayers, route_name="map_top_active", attr="html",
+                    renderer="map_top_active.mako", accept="text/html")
+    config.add_view(view=MapTopPlayers, route_name="map_top_active", attr="json",
+                    renderer="json", accept="application/json")
+
+    config.add_route("map_top_servers", "/map/{id:\d+}/topservers")
+    config.add_view(view=MapTopServers, route_name="map_top_servers", attr="html",
+                    renderer="map_top_servers.mako", accept="text/html")
+    config.add_view(view=MapTopServers, route_name="map_top_servers", attr="json",
+                    renderer="json", accept="application/json")
 
     config.add_route("map_info",      "/map/{id:\d+}")
     config.add_view(map_info,      route_name="map_info",      renderer="map_info.mako")
@@ -167,7 +201,10 @@ def main(global_config, **settings):
     # ADMIN ROUTES
     config.add_forbidden_view(forbidden, renderer="forbidden.mako")
 
-    config.add_route("merge",      "/merge")
-    config.add_view(route_name="merge", renderer="merge.mako", permission="admin")
+    config.add_route("login", "/login")
+    config.add_view(login, route_name="login", check_csrf=True, renderer="json")
+
+    config.add_route("merge", "/admin/merge")
+    config.add_view(merge, route_name="merge", renderer="merge.mako", permission="merge")
 
     return config.make_wsgi_app()