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