]>
Commit | Line | Data |
---|---|---|
81675874 | 1 | #!/usr/bin/python |
2 | ||
940227cb MT |
3 | #import httplib |
4 | #import logging | |
5 | #import markdown2 | |
81675874 | 6 | import os |
940227cb MT |
7 | #import random |
8 | #import re | |
9 | #import socket | |
10 | #import time | |
11 | #import tornado.database | |
12 | #import tornado.locale | |
81675874 | 13 | import tornado.web |
940227cb | 14 | #import unicodedata |
81675874 | 15 | |
940227cb | 16 | import backend |
81675874 | 17 | |
940227cb MT |
18 | from handlers_admin import * |
19 | from handlers_base import * | |
20 | from handlers_download import * | |
21 | from handlers_mirrors import * | |
22 | from handlers_news import * | |
23 | from handlers_planet import * | |
24 | from handlers_stasy import * | |
25 | from handlers_tracker import * | |
feb02477 | 26 | |
d0d074e0 | 27 | |
940227cb MT |
28 | class RootHandler(BaseHandler): |
29 | """ | |
30 | This handler redirects any request directly to /. | |
d0d074e0 | 31 | |
940227cb MT |
32 | It can be used to be compatible with some ancient index urls. |
33 | """ | |
34 | def get(self, *args): | |
35 | self.redirect("/") | |
81675874 | 36 | |
81675874 | 37 | |
940227cb MT |
38 | class LangCompatHandler(BaseHandler): |
39 | """ | |
40 | Redirect links in the old format to current site: | |
81675874 | 41 | |
940227cb MT |
42 | E.g. /en/index -> /index |
43 | """ | |
44 | def get(self, lang, page): | |
45 | self.redirect("/%s" % page) | |
81675874 | 46 | |
feb02477 | 47 | |
940227cb MT |
48 | class IndexHandler(BaseHandler): |
49 | """ | |
50 | This handler displays the welcome page. | |
51 | """ | |
feb02477 | 52 | def get(self): |
940227cb MT |
53 | # Get a list of the most recent news items and put them on the page. |
54 | latest_news = self.news.get_latest(limit=1, locale=self.locale) | |
55 | recent_news = self.news.get_latest(limit=2, locale=self.locale, offset=1) | |
feb02477 | 56 | |
940227cb MT |
57 | return self.render("index.html", |
58 | latest_news=latest_news, recent_news=recent_news) | |
3add293a MT |
59 | |
60 | ||
81675874 | 61 | class StaticHandler(BaseHandler): |
940227cb MT |
62 | """ |
63 | This handler shows the files that are in plain html format. | |
64 | """ | |
81675874 | 65 | @property |
66 | def static_path(self): | |
67 | return os.path.join(self.application.settings["template_path"], "static") | |
68 | ||
69 | @property | |
70 | def static_files(self): | |
71 | ret = [] | |
72 | for filename in os.listdir(self.static_path): | |
73 | if filename.endswith(".html"): | |
74 | ret.append(filename) | |
75 | return ret | |
76 | ||
77 | def get(self, name=None): | |
78 | name = "%s.html" % name | |
79 | ||
80 | if not name in self.static_files: | |
81 | raise tornado.web.HTTPError(404) | |
82 | ||
940227cb | 83 | self.render("static/%s" % name, lang=self.locale.code[:2]) |
feb02477 MT |
84 | |
85 |