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