Merge branch 'master' of github.com:antzucaro/XonStat
[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", renderer="main_index.mako")
24
25     # MAIN SUBMISSION ROUTE
26     config.add_route("stats_submit", "stats/submit")
27     config.add_view(stats_submit, route_name="stats_submit")
28
29     # PLAYER ROUTES
30     config.add_route("player_game_index", "/player/{player_id:\d+}/games")
31     config.add_view(player_game_index, route_name="player_game_index", renderer="player_game_index.mako")
32
33     config.add_route("player_index", "/players")
34     config.add_view(player_index, route_name="player_index", renderer="player_index.mako")
35
36     config.add_route("player_info", "/player/{id:\d+}")
37     config.add_view(player_info, route_name="player_info", renderer="player_info.mako")
38
39     config.add_route("player_accuracy",      "/player/{id:\d+}/accuracy")
40     config.add_route("player_accuracy_json", "/player/{id:\d+}/accuracy.json")
41     config.add_view(player_accuracy_json, route_name="player_accuracy",      renderer="json")
42     config.add_view(player_accuracy_json, route_name="player_accuracy_json", renderer="json")
43
44     config.add_route("player_damage", "/player/{id:\d+}/damage")
45     config.add_view(player_damage_json, route_name="player_damage",
46         renderer="json")
47
48     # GAME ROUTES
49     config.add_route("game_index", "/games")
50     config.add_view(game_index, route_name="game_index", renderer="game_index.mako")
51
52     config.add_route("game_info", "/game/{id:\d+}")
53     config.add_view(game_info, route_name="game_info", renderer="game_info.mako")
54
55     config.add_route("rank_index", "/ranks/{game_type_cd:ctf|dm|tdm|duel}")
56     config.add_view(rank_index, route_name="rank_index", renderer="rank_index.mako")
57
58     # SERVER ROUTES
59     config.add_route("server_index", "/servers")
60     config.add_view(server_index, route_name="server_index", renderer="server_index.mako")
61
62     config.add_route("server_game_index", "/server/{server_id:\d+}/games/page/{page:\d+}")
63     config.add_view(server_game_index, route_name="server_game_index", renderer="server_game_index.mako")
64
65     config.add_route("server_info", "/server/{id:\d+}")
66     config.add_view(server_info, route_name="server_info", renderer="server_info.mako")
67
68     # MAP ROUTES
69     config.add_route("map_index",      "/maps")
70     config.add_route("map_index_json", "/maps.json")
71     config.add_view(map_index,      route_name="map_index",      renderer="map_index.mako")
72     config.add_view(map_index_json, route_name="map_index_json", renderer="json")
73
74     config.add_route("map_info", "/map/{id:\d+}")
75     config.add_view(map_info, route_name="map_info", renderer="map_info.mako")
76
77     # SEARCH ROUTES
78     config.add_route("search", "search")
79     config.add_view(search, route_name="search", renderer="search.mako")
80
81     return config.make_wsgi_app()