]>
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 * | |
8e2e1261 | 20 | from handlers_boot import * |
940227cb | 21 | from handlers_download import * |
c37ec602 | 22 | from handlers_iuse import * |
940227cb MT |
23 | from handlers_mirrors import * |
24 | from handlers_news import * | |
60024cc8 | 25 | from handlers_nopaste import * |
940227cb | 26 | from handlers_planet import * |
de683d7c | 27 | from handlers_rss import * |
940227cb MT |
28 | from handlers_stasy import * |
29 | from handlers_tracker import * | |
7771acea | 30 | from handlers_wishlist import * |
d0d074e0 | 31 | |
940227cb MT |
32 | class RootHandler(BaseHandler): |
33 | """ | |
34 | This handler redirects any request directly to /. | |
d0d074e0 | 35 | |
940227cb MT |
36 | It can be used to be compatible with some ancient index urls. |
37 | """ | |
38 | def get(self, *args): | |
39 | self.redirect("/") | |
81675874 | 40 | |
81675874 | 41 | |
940227cb MT |
42 | class LangCompatHandler(BaseHandler): |
43 | """ | |
44 | Redirect links in the old format to current site: | |
81675874 | 45 | |
940227cb MT |
46 | E.g. /en/index -> /index |
47 | """ | |
48 | def get(self, lang, page): | |
49 | self.redirect("/%s" % page) | |
81675874 | 50 | |
feb02477 | 51 | |
940227cb | 52 | class IndexHandler(BaseHandler): |
de683d7c MT |
53 | rss_url = "/news.rss" |
54 | ||
940227cb MT |
55 | """ |
56 | This handler displays the welcome page. | |
57 | """ | |
feb02477 | 58 | def get(self): |
940227cb | 59 | # Get a list of the most recent news items and put them on the page. |
3d74a9b9 MT |
60 | latest_news = self.news.get_latest(limit=3, locale=self.locale) |
61 | ||
62 | # Get a list of the most recent planet posts. | |
63 | planet_posts = self.planet.get_entries(limit=3) | |
7771acea MT |
64 | |
65 | # Get the latest release. | |
66 | latest_release = self.releases.get_latest() | |
0aab96e0 | 67 | latest_release_unstable = self.releases.get_latest_unstable() |
feb02477 | 68 | |
9d7e697a MT |
69 | # Interesting items from the wishlist. |
70 | wishlist_items = self.wishlist.get_hot_wishes() | |
71 | ||
bb3da2b5 | 72 | return self.render("index.html", latest_news=latest_news, |
9d7e697a | 73 | planet_posts=planet_posts, latest_release=latest_release, |
0aab96e0 | 74 | latest_release_unstable=latest_release_unstable, |
9d7e697a | 75 | wishlist_items=wishlist_items) |
3add293a MT |
76 | |
77 | ||
81675874 | 78 | class StaticHandler(BaseHandler): |
940227cb MT |
79 | """ |
80 | This handler shows the files that are in plain html format. | |
81 | """ | |
81675874 | 82 | @property |
83 | def static_path(self): | |
84 | return os.path.join(self.application.settings["template_path"], "static") | |
85 | ||
86 | @property | |
87 | def static_files(self): | |
54b8df1a MT |
88 | for dir, subdirs, files in os.walk(self.static_path): |
89 | dir = dir[len(self.static_path) + 1:] | |
90 | for file in files: | |
91 | if not file.endswith(".html"): | |
92 | continue | |
93 | yield os.path.join(dir, file) | |
81675874 | 94 | |
95 | def get(self, name=None): | |
96 | name = "%s.html" % name | |
97 | ||
98 | if not name in self.static_files: | |
99 | raise tornado.web.HTTPError(404) | |
100 | ||
940227cb | 101 | self.render("static/%s" % name, lang=self.locale.code[:2]) |
9068dba1 MT |
102 | |
103 | ||
104 | class GeoIPHandler(BaseHandler): | |
105 | def get_address(self): | |
106 | addr = self.get_argument("addr", None) | |
107 | ||
108 | if not addr: | |
109 | addr = self.get_remote_ip() | |
110 | ||
111 | return addr | |
112 | ||
113 | def get(self): | |
114 | addr = self.get_address() | |
115 | ||
116 | peer = self.geoip.get_all(addr) | |
117 | if peer: | |
118 | peer["country_name"] = self.geoip.get_country_name(peer.country) | |
119 | ||
5488a9f4 MT |
120 | mirrors = self.mirrors.get_for_location(peer) |
121 | ||
122 | self.render("geoip/index.html", addr=addr, peer=peer, mirrors=mirrors) | |
e64ce07e MT |
123 | |
124 | ||
125 | class DonateHandler(BaseHandler): | |
126 | def get(self): | |
127 | # Interesting items from the wishlist. | |
128 | wishlist_items = self.wishlist.get_hot_wishes() | |
129 | ||
130 | self.render("donate.html", wishlist_items=wishlist_items) |