]>
git.ipfire.org Git - ipfire.org.git/blob - www/webapp/handlers_base.py
84316ace67d2e1d9e9fc4304d4fe80b10118d0cd
10 class BaseHandler(tornado
.web
.RequestHandler
):
13 def get_account(self
, uid
):
14 # Find the name of the author
15 return self
.accounts
.find(uid
)
17 def get_user_locale(self
):
18 DEFAULT_LOCALE
= tornado
.locale
.get("en_US")
20 [tornado
.locale
.get(l
) for l
in tornado
.locale
.get_supported_locales(None)]
22 # One can append "?locale=de" to mostly and URI on the site and
23 # another output that guessed.
24 locale
= self
.get_argument("locale", None)
26 for l
in ALLOWED_LOCALES
:
27 if not l
.code
.startswith(locale
):
32 # The planet is always in english.
33 if self
.request
.host
== "planet.ipfire.org":
36 # If no locale was provided we guess what the browser sends us
37 locale
= self
.get_browser_locale()
38 if locale
in ALLOWED_LOCALES
:
41 # If no one of the cases above worked we use our default locale
45 def render_args(self
):
47 "hostname" : self
.request
.host
,
48 "lang" : self
.locale
.code
[:2],
49 "rss_url" : self
.rss_url
,
50 "year" : time
.strftime("%Y"),
53 def render(self
, *args
, **_kwargs
):
54 kwargs
= self
.render_args
55 kwargs
.update(_kwargs
)
56 tornado
.web
.RequestHandler
.render(self
, *args
, **kwargs
)
58 def render_string(self
, *args
, **_kwargs
):
59 kwargs
= self
.render_args
60 kwargs
.update(_kwargs
)
61 return tornado
.web
.RequestHandler
.render_string(self
, *args
, **kwargs
)
63 def get_error_html(self
, status_code
, **kwargs
):
64 if status_code
in (404, 500):
67 "exception" : kwargs
.get("exception", None),
68 "message" : httplib
.responses
[status_code
],
70 return self
.render_string("error-%s.html" % status_code
, **render_args
)
72 return tornado
.web
.RequestHandler
.get_error_html(self
, status_code
, **kwargs
)
74 def static_url(self
, path
, static
=True):
75 ret
= tornado
.web
.RequestHandler
.static_url(self
, path
)
78 return "http://static.ipfire.org%s" % ret
84 return backend
.Accounts()
88 return backend
.Banners()
92 return backend
.Memcached()
96 return backend
.Mirrors()
100 return backend
.News()
104 return backend
.Config()
108 return backend
.Releases()
112 return backend
.Banners()
116 return backend
.GeoIP()
120 return backend
.Tracker()
124 return backend
.Planet()