]> git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/__init__.py
Redo submission handling.
[xonotic/xonstat.git] / xonstat / __init__.py
1 import sqlahelper
2 from pyramid_beaker import set_cache_regions_from_settings
3 from pyramid.config import Configurator
4 from pyramid.renderers import JSONP
5 from sqlalchemy import engine_from_config
6 from xonstat.models import initialize_db
7 from xonstat.views import *
8
9 def main(global_config, **settings):
10     """ This function returns a Pyramid WSGI application.
11     """
12     # setup the database engine
13     engine = engine_from_config(settings, 'sqlalchemy.', pool_size=5)
14     sqlahelper.add_engine(engine)
15
16     # initialize database structures
17     initialize_db(engine)
18
19     # set up beaker cache
20     set_cache_regions_from_settings(settings)
21
22     config = Configurator(settings=settings)
23
24     config.add_static_view('static', 'xonstat:static')
25
26     config.add_renderer('jsonp', JSONP(param_name='callback'))
27
28     # ROOT ROUTE
29     config.add_route("main_index", "/")
30     config.add_view(main_index, route_name="main_index", renderer="main_index.mako")
31
32     # MAIN SUBMISSION ROUTE
33     #config.add_route("stats_submit", "stats/submit")
34     #config.add_view(stats_submit, route_name="stats_submit")
35     config.add_route("submit_stats", "stats/submit")
36     config.add_view(submit_stats, route_name="submit_stats")
37
38     # PLAYER ROUTES
39     config.add_route("player_game_index",      "/player/{player_id:\d+}/games")
40     config.add_route("player_game_index_json", "/player/{player_id:\d+}/games.json")
41     config.add_view(player_game_index,      route_name="player_game_index",      renderer="player_game_index.mako")
42     config.add_view(player_game_index_json, route_name="player_game_index_json", renderer="jsonp")
43
44     config.add_route("player_info",      "/player/{id:\d+}")
45     config.add_route("player_info_json", "/player/{id:\d+}.json")
46     config.add_view(player_info,      route_name="player_info",      renderer="player_info.mako")
47     config.add_view(player_info_json, route_name="player_info_json", renderer="jsonp")
48
49     config.add_route("player_hashkey_info_text", "/hashkey/{hashkey}")
50     config.add_view(player_hashkey_info_text, route_name="player_hashkey_info_text", renderer="player_hashkey_info_text.mako")
51
52     #config.add_route("player_hashkey_info_json", "/hashkey/{hashkey}.json")
53     #config.add_view(player_hashkey_info_json, route_name="player_hashkey_info_json", renderer="jsonp")
54
55     config.add_route("player_elo_info_json", "/elo/{hashkey}")
56     config.add_view(player_elo_info_json, route_name="player_elo_info_json", renderer="jsonp")
57
58     config.add_route("player_accuracy",      "/player/{id:\d+}/accuracy")
59     config.add_route("player_accuracy_json", "/player/{id:\d+}/accuracy.json")
60     config.add_view(player_accuracy_json, route_name="player_accuracy",      renderer="jsonp")
61     config.add_view(player_accuracy_json, route_name="player_accuracy_json", renderer="jsonp")
62
63     config.add_route("player_index",      "/players")
64     config.add_route("player_index_json", "/players.json")
65     config.add_view(player_index,      route_name="player_index",      renderer="player_index.mako")
66     config.add_view(player_index_json, route_name="player_index_json", renderer="jsonp")
67
68     config.add_route("player_damage", "/player/{id:\d+}/damage")
69     config.add_view(player_damage_json, route_name="player_damage",
70         renderer="json")
71
72     # GAME ROUTES
73     config.add_route("game_index",      "/games")
74     config.add_route("game_index_json", "/games.json")
75     config.add_view(game_index,      route_name="game_index",      renderer="game_index.mako")
76     config.add_view(game_index_json, route_name="game_index_json", renderer="jsonp")
77
78     config.add_route("game_info",      "/game/{id:\d+}")
79     config.add_route("game_info_json", "/game/{id:\d+}.json")
80     config.add_view(game_info,      route_name="game_info",      renderer="game_info.mako")
81     config.add_view(game_info_json, route_name="game_info_json", renderer="jsonp")
82
83     config.add_route("rank_index",      "/ranks/{game_type_cd:ctf|dm|tdm|duel}")
84     config.add_route("rank_index_json", "/ranks/{game_type_cd:ctf|dm|tdm|duel}.json")
85     config.add_view(rank_index,      route_name="rank_index",      renderer="rank_index.mako")
86     config.add_view(rank_index_json, route_name="rank_index_json", renderer="jsonp")
87
88     config.add_route("game_finder", "/gamefinder")
89     config.add_view(game_finder, route_name="game_finder", renderer="game_finder.mako")
90
91     # SERVER ROUTES
92     config.add_route("server_index",      "/servers")
93     config.add_route("server_index_json", "/servers.json")
94     config.add_view(server_index,      route_name="server_index",      renderer="server_index.mako")
95     config.add_view(server_index_json, route_name="server_index_json", renderer="jsonp")
96
97     config.add_route("server_game_index",      "/server/{server_id:\d+}/games/page/{page:\d+}")
98     config.add_route("server_game_index_json", "/server/{server_id:\d+}/games.json")
99     config.add_view(server_game_index,      route_name="server_game_index",      renderer="server_game_index.mako")
100     config.add_view(server_game_index_json, route_name="server_game_index_json", renderer="jsonp")
101
102     config.add_route("server_info",      "/server/{id:\d+}")
103     config.add_route("server_info_json", "/server/{id:\d+}.json")
104     config.add_view(server_info,      route_name="server_info",      renderer="server_info.mako")
105     config.add_view(server_info_json, route_name="server_info_json", renderer="jsonp")
106
107     # MAP ROUTES
108     config.add_route("map_index",      "/maps")
109     config.add_route("map_index_json", "/maps.json")
110     config.add_view(map_index,      route_name="map_index",      renderer="map_index.mako")
111     config.add_view(map_index_json, route_name="map_index_json", renderer="jsonp")
112
113     config.add_route("map_info",      "/map/{id:\d+}")
114     config.add_route("map_info_json", "/map/{id:\d+}.json")
115     config.add_view(map_info,      route_name="map_info",      renderer="map_info.mako")
116     config.add_view(map_info_json, route_name="map_info_json", renderer="jsonp")
117
118     # SEARCH ROUTES
119     config.add_route("search",      "search")
120     config.add_route("search_json", "search.json")
121     config.add_view(search,      route_name="search",      renderer="search.mako")
122     config.add_view(search_json, route_name="search_json", renderer="jsonp")
123
124     return config.make_wsgi_app()