aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pysite/base_route.py12
-rw-r--r--pysite/route_manager.py5
-rw-r--r--pysite/views/healthcheck.py4
-rw-r--r--pysite/views/index.py6
-rw-r--r--pysite/views/invite.py4
-rw-r--r--templates/.gitkeep0
-rw-r--r--templates/index.html10
7 files changed, 29 insertions, 12 deletions
diff --git a/pysite/base_route.py b/pysite/base_route.py
index 17e9aee3..16bf0984 100644
--- a/pysite/base_route.py
+++ b/pysite/base_route.py
@@ -1,23 +1,29 @@
# coding=utf-8
-from flask import Flask
+from flask import Flask, render_template
from flask.views import MethodView
__author__ = "Gareth Coles"
class BaseView(MethodView):
+ def render(self, *template_names, **context):
+ # thin wrapper here in case it needs to be modified later
+ return render_template(template_names, **context)
+
+
+class RouteView(BaseView):
path = None #: str
name = None #: str
@classmethod
- def setup(cls: "BaseView", app: Flask):
+ def setup(cls: "RouteView", 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):
+class ErrorView(BaseView):
name = None #: str
error_code = None #: int
diff --git a/pysite/route_manager.py b/pysite/route_manager.py
index 501076b7..f922be6a 100644
--- a/pysite/route_manager.py
+++ b/pysite/route_manager.py
@@ -5,7 +5,7 @@ import os
from flask import Flask
-from pysite.base_route import BaseView, ErrorView
+from pysite.base_route import BaseView, ErrorView, RouteView
__author__ = "Gareth Coles"
@@ -35,7 +35,8 @@ class RouteManager:
inspect.isclass(cls) and
cls is not BaseView and
cls is not ErrorView and
- (BaseView in cls.__mro__ or ErrorView in cls.__mro__)
+ cls is not RouteView and
+ BaseView in cls.__mro__
):
cls.setup(self.app)
print(f"View loaded: {cls.name: <25} ({module.__name__}.{cls_name})")
diff --git a/pysite/views/healthcheck.py b/pysite/views/healthcheck.py
index 660c8a96..088bc7b3 100644
--- a/pysite/views/healthcheck.py
+++ b/pysite/views/healthcheck.py
@@ -1,13 +1,13 @@
# coding=utf-8
from flask import jsonify
-from pysite.base_route import BaseView
+from pysite.base_route import RouteView
__author__ = "Gareth Coles"
-class IndexView(BaseView):
+class IndexView(RouteView):
path = "/healthcheck"
name = "healthcheck"
diff --git a/pysite/views/index.py b/pysite/views/index.py
index 2e779003..040332cc 100644
--- a/pysite/views/index.py
+++ b/pysite/views/index.py
@@ -1,12 +1,12 @@
# coding=utf-8
-from pysite.base_route import BaseView
+from pysite.base_route import RouteView
__author__ = "Gareth Coles"
-class IndexView(BaseView):
+class IndexView(RouteView):
path = "/"
name = "index"
def get(self):
- return "Coming soon:tm:"
+ return self.render("index.html")
diff --git a/pysite/views/invite.py b/pysite/views/invite.py
index d035fc99..07ddc830 100644
--- a/pysite/views/invite.py
+++ b/pysite/views/invite.py
@@ -1,13 +1,13 @@
# coding=utf-8
from flask import redirect
-from pysite.base_route import BaseView
+from pysite.base_route import RouteView
__author__ = "Gareth Coles"
-class InviteView(BaseView):
+class InviteView(RouteView):
path = "/invite"
name = "invite"
diff --git a/templates/.gitkeep b/templates/.gitkeep
deleted file mode 100644
index e69de29b..00000000
--- a/templates/.gitkeep
+++ /dev/null
diff --git a/templates/index.html b/templates/index.html
new file mode 100644
index 00000000..07bd4541
--- /dev/null
+++ b/templates/index.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Python | Home</title>
+</head>
+<body>
+<p>Coming soon:tm:</p>
+</body>
+</html> \ No newline at end of file