aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/base_route.py
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-02-05 12:22:49 +0000
committerGravatar Gareth Coles <[email protected]>2018-02-05 12:22:49 +0000
commitbeaa61362aed31f229c935a347e382024eee5a90 (patch)
tree4d9cf54e44b7fea4124389098fd0fa37a17cdad9 /pysite/base_route.py
parentAdd templates & static folder with .gitkeep's (diff)
Dynamic route loader; proper application structure
Also fixed flake8-imports getting the other wrong
Diffstat (limited to 'pysite/base_route.py')
-rw-r--r--pysite/base_route.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/pysite/base_route.py b/pysite/base_route.py
new file mode 100644
index 00000000..76338280
--- /dev/null
+++ b/pysite/base_route.py
@@ -0,0 +1,29 @@
+# coding=utf-8
+from flask import Flask
+from flask.views import MethodView
+
+__author__ = "Gareth Coles"
+
+
+class BaseView(MethodView):
+ path = None #: str
+ name = None #: str
+
+ @classmethod
+ def setup(cls: "BaseView", app: Flask):
+ if not cls.path or not cls.name:
+ raise RuntimeError("Route views must have both `path` and `name` defined")
+
+ app.add_url_rule(cls.path, view_func=cls.as_view(cls.name))
+
+
+class ErrorView(MethodView):
+ name = None #: str
+ error_code = None #: int
+
+ @classmethod
+ def setup(cls: "ErrorView", app: Flask):
+ if not cls.name or not cls.error_code:
+ raise RuntimeError("Error views must have both `name` and `error_code` defined")
+
+ app._register_error_handler(None, 404, cls.as_view(cls.name))