]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - webapp/handlers.py
fireinfo: Shorten an other AMD APU processor
[people/shoehn/ipfire.org.git] / webapp / handlers.py
1 #!/usr/bin/python
2
3 #import httplib
4 #import logging
5 #import markdown2
6 import os
7 #import random
8 #import re
9 #import socket
10 #import time
11 #import tornado.database
12 #import tornado.locale
13 import tornado.web
14 #import unicodedata
15
16 import backend
17
18 from handlers_accounts import *
19 from handlers_admin import *
20 from handlers_base import *
21 from handlers_boot import *
22 from handlers_download import *
23 from handlers_fireinfo import *
24 from handlers_iuse import *
25 from handlers_mirrors import *
26 from handlers_news import *
27 from handlers_nopaste import *
28 from handlers_planet import *
29 from handlers_rss import *
30 from handlers_talk import *
31 from handlers_tracker import *
32 from handlers_wishlist import *
33
34 class RootHandler(BaseHandler):
35 """
36 This handler redirects any request directly to /.
37
38 It can be used to be compatible with some ancient index urls.
39 """
40 def get(self, *args):
41 self.redirect("/")
42
43
44 class LangCompatHandler(BaseHandler):
45 """
46 Redirect links in the old format to current site:
47
48 E.g. /en/index -> /index
49 """
50 def get(self, lang, page):
51 self.redirect("/%s" % page)
52
53
54 class IndexHandler(BaseHandler):
55 rss_url = "/news.rss"
56
57 """
58 This handler displays the welcome page.
59 """
60 def get(self):
61 # Get a list of the most recent news items and put them on the page.
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)
66
67 # Get the latest release.
68 latest_release = self.releases.get_latest()
69 latest_release_unstable = self.releases.get_latest_unstable()
70
71 # Interesting items from the wishlist.
72 wishlist_items = self.wishlist.get_hot_wishes()
73
74 return self.render("index.html", latest_news=latest_news,
75 planet_posts=planet_posts, latest_release=latest_release,
76 latest_release_unstable=latest_release_unstable,
77 wishlist_items=wishlist_items)
78
79
80 class StaticHandler(BaseHandler):
81 """
82 This handler shows the files that are in plain html format.
83 """
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):
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)
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
103 self.render("static/%s" % name, lang=self.locale.code[:2])
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
122 mirrors = self.mirrors.get_for_location(peer)
123
124 self.render("geoip/index.html", addr=addr, peer=peer, mirrors=mirrors)
125
126
127 class DonateHandler(BaseHandler):
128 def get(self):
129 # Interesting items from the wishlist.
130 wishlist_items = self.wishlist.get_hot_wishes()
131
132 self.render("donate.html", wishlist_items=wishlist_items)