]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blame - www/webapp/__init__.py
Merge branch 'next' of ssh://ms@git.ipfire.org/pub/git/ipfire.org into next
[people/shoehn/ipfire.org.git] / www / webapp / __init__.py
CommitLineData
81675874 1#/usr/bin/python
2
3import os.path
8ccd2ff0
MT
4import simplejson
5
6simplejson._default_decoder = simplejson.JSONDecoder(encoding="latin-1")
81675874 7
8import tornado.locale
9import tornado.options
10import tornado.web
11
8ccd2ff0
MT
12from handlers import *
13from ui_modules import *
81675874 14
15BASEDIR = os.path.join(os.path.dirname(__file__), "..")
16
17tornado.locale.load_translations(os.path.join(BASEDIR, "translations"))
18tornado.options.enable_pretty_logging()
19
20class Application(tornado.web.Application):
21 def __init__(self):
81675874 22 settings = dict(
23 cookie_secret = "aXBmaXJlY29va2llc2VjcmV0Cg==",
24 #debug = True,
25 gzip = True,
81675874 26 template_path = os.path.join(BASEDIR, "templates"),
27 ui_modules = {
28 "Build" : BuildModule,
29 "Menu" : MenuModule,
30 "MenuItem" : MenuItemModule,
31 "NewsItem" : NewsItemModule,
32 "ReleaseItem" : ReleaseItemModule,
33 "SidebarBanner" : SidebarBannerModule,
34 "SidebarItem" : SidebarItemModule,
35 "SidebarRelease" : SidebarReleaseModule,
36 },
37 xsrf_cookies = True,
38 )
5cf160e0 39
ae0228e1
MT
40 tornado.web.Application.__init__(self, **settings)
41
42 self.settings["static_path"] = static_path = os.path.join(BASEDIR, "static")
43 static_handlers = [
44 (r"/static/(.*)", tornado.web.StaticFileHandler, dict(path = static_path)),
45 (r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = static_path)),
46 (r"/(robots\.txt)", tornado.web.StaticFileHandler, dict(path = static_path)),
47 ]
48
49 self.add_handlers(r"www\.ipfire\.org", [
81675874 50 # Entry sites that lead the user to index
51 (r"/", MainHandler),
52 (r"/[A-Za-z]{2}/?", MainHandler),
53 #
54 (r"/[A-Za-z]{2}/index", IndexHandler),
55 (r"/[A-Za-z]{2}/news", NewsHandler),
56 (r"/[A-Za-z]{2}/builds", BuildHandler),
57 (r"/[A-Za-z]{2}/translations?", TranslationHandler),
58 # Download sites
59 (r"/[A-Za-z]{2}/downloads?", DownloadHandler),
60 (r"/[A-Za-z]{2}/downloads?/all", DownloadAllHandler),
61 (r"/[A-Za-z]{2}/downloads?/development", DownloadDevelopmentHandler),
62 (r"/[A-Za-z]{2}/downloads?/torrents", DownloadTorrentHandler),
63 # API
64 (r"/api/cluster_info", ApiClusterInfoHandler),
65 # Always the last rule
66 (r"/[A-Za-z]{2}/(.*)", StaticHandler),
ae0228e1 67 ] + static_handlers)
81675874 68
5cf160e0 69 # download.ipfire.org
ae0228e1 70 self.add_handlers(r"download\.ipfire\.org", [
5cf160e0
MT
71 (r"/", MainHandler),
72 (r"/[A-Za-z]{2}/index", DownloadHandler),
ae0228e1 73 ] + static_handlers)
5cf160e0
MT
74
75 # source.ipfire.org
ae0228e1 76 self.add_handlers(r"source\.ipfire\.org", [
5cf160e0 77 (r"/", MainHandler),
e2b0b0e4 78 (r"/[A-Za-z]{2}/index", SourceHandler),
ae0228e1 79 ] + static_handlers)
5cf160e0
MT
80
81 # torrent.ipfire.org
ae0228e1 82 self.add_handlers(r"torrent\.ipfire\.org", [
5cf160e0
MT
83 (r"/", MainHandler),
84 (r"/[A-Za-z]{2}/index", DownloadTorrentHandler),
ae0228e1 85 ] + static_handlers)
5cf160e0
MT
86
87 # tracker.ipfire.org
ae0228e1 88 self.add_handlers(r"tracker\.ipfire\.org", [
5cf160e0
MT
89 (r"/", MainHandler),
90 (r"/[A-Za-z]{2}/index", DownloadTorrentHandler),
ae0228e1
MT
91 ] + static_handlers)
92
93 # ipfire.org
94 self.add_handlers(r"ipfire\.org", [
95 (r".*", tornado.web.RedirectHandler, { "url" : "http://www.ipfire.org" })
5cf160e0 96 ])