diff options
author | 2018-02-05 20:26:54 +0100 | |
---|---|---|
committer | 2018-02-05 20:26:54 +0100 | |
commit | 80a1ab522e7a49f3ea1168d8658fbff293c866f1 (patch) | |
tree | 206a45b1a68c273db43ad04b105bcd3e7c48f565 /pysite/route_manager.py | |
parent | Dynamic route loader; proper application structure (diff) |
Major update
- Switch to Japronto
- More linters
- Rewrite route handling
- Rewrite error handling
- Rewrite static handling
- Error when no `Index` propery is found
- Probably some more stuff? idk
Code needs testing; Maybe we could use pytest?
Signed-off-by: martmists <[email protected]>
Diffstat (limited to 'pysite/route_manager.py')
-rw-r--r-- | pysite/route_manager.py | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/pysite/route_manager.py b/pysite/route_manager.py deleted file mode 100644 index 501076b7..00000000 --- a/pysite/route_manager.py +++ /dev/null @@ -1,41 +0,0 @@ -# coding=utf-8 -import importlib -import inspect -import os - -from flask import Flask - -from pysite.base_route import BaseView, ErrorView - -__author__ = "Gareth Coles" - - -class RouteManager: - def __init__(self): - self.app = Flask(__name__) - self.app.secret_key = os.environ.get("WEBPAGE_SECRET_KEY") - - self.load_views() - - def run(self): - self.app.run(port=int(os.environ.get("WEBPAGE_PORT")), debug=False) - - def load_views(self, location="pysite/views"): - for filename in os.listdir(location): - if os.path.isdir(f"{location}/{filename}"): - # Recurse if it's a directory; load ALL the views! - self.load_views(location=f"{location}/{filename}") - continue - - if filename.endswith(".py") and not filename.startswith("__init__"): - module = importlib.import_module(f"{location}/{filename}".replace("/", ".")[:-3]) - - for cls_name, cls in inspect.getmembers(module): - if ( - inspect.isclass(cls) and - cls is not BaseView and - cls is not ErrorView and - (BaseView in cls.__mro__ or ErrorView in cls.__mro__) - ): - cls.setup(self.app) - print(f"View loaded: {cls.name: <25} ({module.__name__}.{cls_name})") |