aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/base_route.py
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-02-06 01:01:59 +0000
committerGravatar Gareth Coles <[email protected]>2018-02-06 01:01:59 +0000
commit1fed2a2cdcacd3bfcc0b69f7b1a1bb536c8e5268 (patch)
tree6ec570b58a6652a7ac935c75b4296bcf5f4509b5 /pysite/base_route.py
parentflake8-todo too pedantic for us - hopefully travis didn't cache it (diff)
Revert "Finally fix this garbage"
This reverts commit 57abb43
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..17e9aee3
--- /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, cls.error_code, cls.as_view(cls.name))