]>
git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - www/webapp/handlers_base.py
10 class BaseHandler(tornado
.web
.RequestHandler
):
11 def get_account(self
, uid
):
12 # Find the name of the author
13 return self
.accounts
.find(uid
)
15 def get_user_locale(self
):
16 DEFAULT_LOCALE
= tornado
.locale
.get("en_US")
18 [tornado
.locale
.get(l
) for l
in tornado
.locale
.get_supported_locales(None)]
20 # One can append "?locale=de" to mostly and URI on the site and
21 # another output that guessed.
22 locale
= self
.get_argument("locale", None)
24 locale
= tornado
.locale
.get(locale
)
25 for locale
in ALLOWED_LOCALES
:
28 # If no locale was provided we guess what the browser sends us
29 locale
= self
.get_browser_locale()
30 if locale
in ALLOWED_LOCALES
:
33 # If no one of the cases above worked we use our default locale
37 def render_args(self
):
39 "hostname" : self
.request
.host
,
40 "lang" : self
.locale
.code
[:2],
41 "year" : time
.strftime("%Y"),
44 def render(self
, *args
, **kwargs
):
45 kwargs
.update(self
.render_args
)
46 tornado
.web
.RequestHandler
.render(self
, *args
, **kwargs
)
48 def render_string(self
, *args
, **kwargs
):
49 kwargs
.update(self
.render_args
)
50 return tornado
.web
.RequestHandler
.render_string(self
, *args
, **kwargs
)
52 def get_error_html(self
, status_code
, **kwargs
):
53 if status_code
in (404, 500):
56 "exception" : kwargs
.get("exception", None),
57 "message" : httplib
.responses
[status_code
],
59 return self
.render_string("error-%s.html" % status_code
, **render_args
)
61 return tornado
.web
.RequestHandler
.get_error_html(self
, status_code
, **kwargs
)
65 return backend
.Accounts()
69 return backend
.Banners()
73 return backend
.Mirrors()
81 return backend
.Config()
85 return backend
.Releases()
89 return backend
.Banners()
93 return backend
.GeoIP()
97 return backend
.Tracker()