]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - www/webapp/handlers.py
Add job that updates the file database from the main mirror.
[people/shoehn/ipfire.org.git] / www / webapp / handlers.py
1 #!/usr/bin/python
2
3 #import httplib
4 #import logging
5 #import markdown2
6 import os
7 #import random
8 #import re
9 #import socket
10 #import time
11 #import tornado.database
12 #import tornado.locale
13 import tornado.web
14 #import unicodedata
15
16 import backend
17
18 from handlers_admin import *
19 from handlers_base import *
20 from handlers_download import *
21 from handlers_iuse import *
22 from handlers_mirrors import *
23 from handlers_news import *
24 from handlers_planet import *
25 from handlers_rss import *
26 from handlers_stasy import *
27 from handlers_tracker import *
28
29
30 class RootHandler(BaseHandler):
31 """
32 This handler redirects any request directly to /.
33
34 It can be used to be compatible with some ancient index urls.
35 """
36 def get(self, *args):
37 self.redirect("/")
38
39
40 class LangCompatHandler(BaseHandler):
41 """
42 Redirect links in the old format to current site:
43
44 E.g. /en/index -> /index
45 """
46 def get(self, lang, page):
47 self.redirect("/%s" % page)
48
49
50 class IndexHandler(BaseHandler):
51 rss_url = "/news.rss"
52
53 """
54 This handler displays the welcome page.
55 """
56 def get(self):
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)
59 recent_news = self.news.get_latest(limit=3, locale=self.locale, offset=1)
60
61 return self.render("index.html",
62 latest_news=latest_news, recent_news=recent_news)
63
64
65 class StaticHandler(BaseHandler):
66 """
67 This handler shows the files that are in plain html format.
68 """
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
87 self.render("static/%s" % name, lang=self.locale.code[:2])
88
89