From: Michael Tremer Date: Thu, 12 Jul 2018 17:35:40 +0000 (+0100) Subject: web: Replace wildcard static handler X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=45592df51dad4f2edddfbca13f1b9ef29fc1499a;p=ipfire.org.git web: Replace wildcard static handler Signed-off-by: Michael Tremer --- diff --git a/src/web/__init__.py b/src/web/__init__.py index 84f4581a..e35322c8 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -102,12 +102,19 @@ class Application(tornado.web.Application): # RSS feed (r"/news.rss", RSSNewsHandler), + # Static Pages + (r"/artwork", StaticHandler, { "template" : "artwork.html" }), + (r"/chat", StaticHandler, { "template" : "chat.html" }), + (r"/features", StaticHandler, { "template" : "features.html" }), + (r"/get-involved", StaticHandler, { "template" : "get-involved.html" }), + (r"/get-started", StaticHandler, { "template" : "get-started.html" }), + (r"/get-support", StaticHandler, { "template" : "get-support.html" }), + (r"/hardware", StaticHandler, { "template" : "hardware.html" }), + (r"/legal", StaticHandler, { "template" : "legal.html" }), + # Handle old pages that have moved elsewhere (r"/imprint", tornado.web.RedirectHandler, { "url" : "/legal" }), (r"/(de|en)/(.*)", LangCompatHandler), - - # Always the last rule - (r"/(.*)", StaticHandler), ]) # downloads.ipfire.org @@ -260,7 +267,7 @@ class Application(tornado.web.Application): ] + authentication_handlers) # ipfire.org - self.add_handlers(r".*", [ + self.add_handlers(r"ipfire\.org", [ (r".*", tornado.web.RedirectHandler, { "url" : "https://www.ipfire.org" }) ]) diff --git a/src/web/handlers.py b/src/web/handlers.py index 79e3f4d9..cc710d2b 100644 --- a/src/web/handlers.py +++ b/src/web/handlers.py @@ -70,32 +70,6 @@ class IndexHandler(BaseHandler): return latest_news[:count] -class StaticHandler(BaseHandler): - """ - This handler shows the files that are in plain html format. - """ - @property - def static_path(self): - return os.path.join(self.application.settings["template_path"], "static") - - @property - def static_files(self): - for dir, subdirs, files in os.walk(self.static_path): - dir = dir[len(self.static_path) + 1:] - for file in files: - if not file.endswith(".html"): - continue - yield os.path.join(dir, file) - - def get(self, name=None): - name = "%s.html" % name - - if not name in self.static_files: - raise tornado.web.HTTPError(404) - - self.render("static/%s" % name, lang=self.locale.code[:2]) - - class GeoIPHandler(BaseHandler): def get_address(self): addr = self.get_argument("addr", None) @@ -165,3 +139,11 @@ class DownloadHandler(BaseHandler): release = self.releases.get_latest() self.render("download.html", release=release) + + +class StaticHandler(BaseHandler): + def initialize(self, template): + self._template = template + + def get(self): + self.render("static/%s" % self._template)