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