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