]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blame - www/webapp/handlers.py
Add FB banner.
[people/shoehn/ipfire.org.git] / www / 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 *
20from handlers_download import *
c37ec602 21from handlers_iuse import *
940227cb
MT
22from handlers_mirrors import *
23from handlers_news import *
24from handlers_planet import *
de683d7c 25from handlers_rss import *
940227cb
MT
26from handlers_stasy import *
27from handlers_tracker import *
feb02477 28
d0d074e0 29
940227cb
MT
30class RootHandler(BaseHandler):
31 """
32 This handler redirects any request directly to /.
d0d074e0 33
940227cb
MT
34 It can be used to be compatible with some ancient index urls.
35 """
36 def get(self, *args):
37 self.redirect("/")
81675874 38
81675874 39
940227cb
MT
40class LangCompatHandler(BaseHandler):
41 """
42 Redirect links in the old format to current site:
81675874 43
940227cb
MT
44 E.g. /en/index -> /index
45 """
46 def get(self, lang, page):
47 self.redirect("/%s" % page)
81675874 48
feb02477 49
940227cb 50class IndexHandler(BaseHandler):
de683d7c
MT
51 rss_url = "/news.rss"
52
940227cb
MT
53 """
54 This handler displays the welcome page.
55 """
feb02477 56 def get(self):
940227cb
MT
57 # Get a list of the most recent news items and put them on the page.
58 latest_news = self.news.get_latest(limit=1, locale=self.locale)
57a86240 59 recent_planets = self.planet.get_entries(limit=1)
feb02477 60
940227cb 61 return self.render("index.html",
57a86240 62 latest_news=latest_news, recent_planets=recent_planets)
3add293a
MT
63
64
81675874 65class StaticHandler(BaseHandler):
940227cb
MT
66 """
67 This handler shows the files that are in plain html format.
68 """
81675874 69 @property
70 def static_path(self):
71 return os.path.join(self.application.settings["template_path"], "static")
72
73 @property
74 def static_files(self):
75 ret = []
76 for filename in os.listdir(self.static_path):
77 if filename.endswith(".html"):
78 ret.append(filename)
79 return ret
80
81 def get(self, name=None):
82 name = "%s.html" % name
83
84 if not name in self.static_files:
85 raise tornado.web.HTTPError(404)
86
940227cb 87 self.render("static/%s" % name, lang=self.locale.code[:2])
feb02477
MT
88
89