]> git.ipfire.org Git - ipfire.org.git/blob - webapp/handlers.py
Major update of the webapp.
[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_admin import *
19 from handlers_base import *
20 from handlers_boot import *
21 from handlers_download import *
22 from handlers_iuse import *
23 from handlers_mirrors import *
24 from handlers_news import *
25 from handlers_nopaste import *
26 from handlers_planet import *
27 from handlers_rss import *
28 from handlers_stasy import *
29 from handlers_tracker import *
30 from handlers_wishlist import *
31
32 class RootHandler(BaseHandler):
33 """
34 This handler redirects any request directly to /.
35
36 It can be used to be compatible with some ancient index urls.
37 """
38 def get(self, *args):
39 self.redirect("/")
40
41
42 class LangCompatHandler(BaseHandler):
43 """
44 Redirect links in the old format to current site:
45
46 E.g. /en/index -> /index
47 """
48 def get(self, lang, page):
49 self.redirect("/%s" % page)
50
51
52 class IndexHandler(BaseHandler):
53 rss_url = "/news.rss"
54
55 """
56 This handler displays the welcome page.
57 """
58 def get(self):
59 # Get a list of the most recent news items and put them on the page.
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)
64
65 # Get the latest release.
66 latest_release = self.releases.get_latest()
67
68 # Interesting items from the wishlist.
69 wishlist_items = self.wishlist.get_hot_wishes()
70
71 return self.render("index.html", latest_news=latest_news,
72 planet_posts=planet_posts, latest_release=latest_release,
73 wishlist_items=wishlist_items)
74
75
76 class StaticHandler(BaseHandler):
77 """
78 This handler shows the files that are in plain html format.
79 """
80 @property
81 def static_path(self):
82 return os.path.join(self.application.settings["template_path"], "static")
83
84 @property
85 def static_files(self):
86 for dir, subdirs, files in os.walk(self.static_path):
87 dir = dir[len(self.static_path) + 1:]
88 for file in files:
89 if not file.endswith(".html"):
90 continue
91 yield os.path.join(dir, file)
92
93 def get(self, name=None):
94 name = "%s.html" % name
95
96 if not name in self.static_files:
97 raise tornado.web.HTTPError(404)
98
99 self.render("static/%s" % name, lang=self.locale.code[:2])
100
101
102 class GeoIPHandler(BaseHandler):
103 def get_address(self):
104 addr = self.get_argument("addr", None)
105
106 if not addr:
107 addr = self.get_remote_ip()
108
109 return addr
110
111 def get(self):
112 addr = self.get_address()
113
114 peer = self.geoip.get_all(addr)
115 if peer:
116 peer["country_name"] = self.geoip.get_country_name(peer.country)
117
118 self.render("geoip/index.html", addr=addr, peer=peer)