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