]>
git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - webapp/handlers.py
11 #import tornado.database
12 #import tornado.locale
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 *
34 class RootHandler(BaseHandler
):
36 This handler redirects any request directly to /.
38 It can be used to be compatible with some ancient index urls.
44 class LangCompatHandler(BaseHandler
):
46 Redirect links in the old format to current site:
48 E.g. /en/index -> /index
50 def get(self
, lang
, page
):
51 self
.redirect("/%s" % page
)
54 class IndexHandler(BaseHandler
):
58 This handler displays the welcome page.
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
)
64 # Get a list of the most recent planet posts.
65 planet_posts
= self
.planet
.get_entries(limit
=3)
67 # Get the latest release.
68 latest_release
= self
.releases
.get_latest()
69 latest_release_unstable
= self
.releases
.get_latest_unstable()
71 # Interesting items from the wishlist.
72 wishlist_items
= self
.wishlist
.get_hot_wishes()
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
)
80 class StaticHandler(BaseHandler
):
82 This handler shows the files that are in plain html format.
85 def static_path(self
):
86 return os
.path
.join(self
.application
.settings
["template_path"], "static")
89 def static_files(self
):
90 for dir, subdirs
, files
in os
.walk(self
.static_path
):
91 dir = dir[len(self
.static_path
) + 1:]
93 if not file.endswith(".html"):
95 yield os
.path
.join(dir, file)
97 def get(self
, name
=None):
98 name
= "%s.html" % name
100 if not name
in self
.static_files
:
101 raise tornado
.web
.HTTPError(404)
103 self
.render("static/%s" % name
, lang
=self
.locale
.code
[:2])
106 class GeoIPHandler(BaseHandler
):
107 def get_address(self
):
108 addr
= self
.get_argument("addr", None)
111 addr
= self
.get_remote_ip()
116 addr
= self
.get_address()
118 peer
= self
.geoip
.get_all(addr
)
120 peer
["country_name"] = self
.geoip
.get_country_name(peer
.country
)
122 mirrors
= self
.mirrors
.get_for_location(peer
)
124 self
.render("geoip/index.html", addr
=addr
, peer
=peer
, mirrors
=mirrors
)
127 class DonateHandler(BaseHandler
):
129 # Interesting items from the wishlist.
130 wishlist_items
= self
.wishlist
.get_hot_wishes()
132 self
.render("donate.html", wishlist_items
=wishlist_items
)