]> git.ipfire.org Git - ipfire.org.git/commitdiff
web: Replace wildcard static handler
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 12 Jul 2018 17:35:40 +0000 (18:35 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 12 Jul 2018 17:35:40 +0000 (18:35 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/web/__init__.py
src/web/handlers.py

index 84f4581adcc2506b7df56261a09acae2cff7cfe3..e35322c894523d5ad44d2bec94448321fda5337d 100644 (file)
@@ -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" })
                ])
 
index 79e3f4d96c162ad088d02d3f1ed831f92d5b5b03..cc710d2bdea2df3bc3479f364f23ea0f4a6c2dbf 100644 (file)
@@ -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)