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