]> git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/__init__.py
Merge remote-tracking branch 'antzucaro/master'
[xonotic/xonstat.git] / xonstat / __init__.py
1 import sqlahelper
2 from pyramid.config import Configurator
3 from sqlalchemy import engine_from_config
4 from xonstat.models import initialize_db
5 from xonstat.views import * 
6
7 def main(global_config, **settings):
8     """ This function returns a Pyramid WSGI application.
9     """
10     # setup the database engine
11     engine = engine_from_config(settings, 'sqlalchemy.')
12     sqlahelper.add_engine(engine)
13
14     # initialize database structures
15     initialize_db(engine)
16
17     config = Configurator(settings=settings)
18
19     config.add_static_view('static', 'xonstat:static')
20
21     # ROOT ROUTE
22     config.add_route("main_index", "/")
23     config.add_view(main_index, route_name="main_index",
24         renderer="main_index.mako")
25
26     # MAIN SUBMISSION ROUTE
27     config.add_route("stats_submit", "stats/submit")
28     config.add_view(stats_submit, route_name="stats_submit")
29
30     # PLAYER ROUTES
31     config.add_route("player_game_index",
32             "/player/{player_id:\d+}/games")
33     config.add_view(player_game_index, route_name="player_game_index",
34         renderer="player_game_index.mako")
35
36     config.add_route("player_index", "/players")
37     config.add_view(player_index, route_name="player_index",
38         renderer="player_index.mako")
39
40     config.add_route("player_info", "/player/{id:\d+}")
41     config.add_view(player_info, route_name="player_info",
42         renderer="player_info.mako")
43
44     config.add_route("player_accuracy", "/player/{id:\d+}/accuracy")
45     config.add_view(player_accuracy, route_name="player_accuracy",
46         renderer="json")
47
48     # GAME ROUTES
49     config.add_route("game_index", "/games")
50     config.add_view(game_index, route_name="game_index",
51         renderer="game_index.mako")
52
53     config.add_route("game_info", "/game/{id:\d+}")
54     config.add_view(game_info, route_name="game_info",
55         renderer="game_info.mako")
56
57     config.add_route("rank_index", "/ranks/{game_type_cd:ctf|dm|tdm|duel}")
58     config.add_view(rank_index, route_name="rank_index",
59         renderer="rank_index.mako")
60
61     # SERVER ROUTES
62     config.add_route("server_index", "/servers")
63     config.add_view(server_index, route_name="server_index",
64         renderer="server_index.mako")
65
66     config.add_route("server_game_index",
67         "/server/{server_id:\d+}/games/page/{page:\d+}")
68     config.add_view(server_game_index, route_name="server_game_index",
69         renderer="server_game_index.mako")
70
71     config.add_route("server_info", "/server/{id:\d+}")
72     config.add_view(server_info, route_name="server_info",
73         renderer="server_info.mako")
74
75     # MAP ROUTES
76     config.add_route("map_index_json", "/maps.json")
77     config.add_view(map_index_json, route_name="map_index_json",
78         renderer="json")
79
80     config.add_route("map_index", "/maps")
81     config.add_view(map_index, route_name="map_index",
82         renderer="map_index.mako")
83
84     config.add_route("map_info", "/map/{id:\d+}")
85     config.add_view(map_info, route_name="map_info",
86         renderer="map_info.mako")
87
88     # SEARCH ROUTES
89     config.add_route("search", "search")
90     config.add_view(search, route_name="search",
91         renderer="search.mako")
92
93     return config.make_wsgi_app()