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