From ef8e96157f60ba0813cab72a90a6e8e92b44b6f0 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 21 Feb 2018 09:30:05 +0000 Subject: Rearrange views and templates --- pysite/route_manager.py | 1 + pysite/views/error_handlers/http_404.py | 12 ++++++++++++ pysite/views/error_handlers/http_5xx.py | 12 ++++++++++++ pysite/views/main/error_handlers/__init__.py | 1 - pysite/views/main/error_handlers/http_404.py | 12 ------------ pysite/views/main/error_handlers/http_5xx.py | 12 ------------ pysite/views/main/index.py | 2 +- pysite/views/main/ws_test.py | 2 +- pysite/views/staff/index.py | 2 +- templates/base.html | 18 ------------------ templates/index.html | 9 --------- templates/main/base.html | 18 ++++++++++++++++++ templates/main/index.html | 9 +++++++++ templates/main/navigation.html | 19 +++++++++++++++++++ templates/main/ws_test.html | 24 ++++++++++++++++++++++++ templates/navigation.html | 19 ------------------- templates/staff.html | 9 --------- templates/staff/staff.html | 9 +++++++++ templates/ws_test.html | 24 ------------------------ 19 files changed, 107 insertions(+), 107 deletions(-) create mode 100644 pysite/views/error_handlers/http_404.py create mode 100644 pysite/views/error_handlers/http_5xx.py delete mode 100644 pysite/views/main/error_handlers/__init__.py delete mode 100644 pysite/views/main/error_handlers/http_404.py delete mode 100644 pysite/views/main/error_handlers/http_5xx.py delete mode 100644 templates/base.html delete mode 100644 templates/index.html create mode 100644 templates/main/base.html create mode 100644 templates/main/index.html create mode 100644 templates/main/navigation.html create mode 100644 templates/main/ws_test.html delete mode 100644 templates/navigation.html delete mode 100644 templates/staff.html create mode 100644 templates/staff/staff.html delete mode 100644 templates/ws_test.html diff --git a/pysite/route_manager.py b/pysite/route_manager.py index 105a8f86..494dfbde 100644 --- a/pysite/route_manager.py +++ b/pysite/route_manager.py @@ -36,6 +36,7 @@ class RouteManager: self.main_blueprint = Blueprint("main", __name__) self.log.debug(f"Loading Blueprint: {self.main_blueprint.name}") self.load_views(self.main_blueprint, "pysite/views/main") + self.load_views(self.main_blueprint, "pysite/views/error_handlers") self.app.register_blueprint(self.main_blueprint) self.log.debug("") diff --git a/pysite/views/error_handlers/http_404.py b/pysite/views/error_handlers/http_404.py new file mode 100644 index 00000000..1d557d9b --- /dev/null +++ b/pysite/views/error_handlers/http_404.py @@ -0,0 +1,12 @@ +# coding=utf-8 +from werkzeug.exceptions import NotFound + +from pysite.base_route import ErrorView + + +class Error404View(ErrorView): + name = "error_404" + error_code = 404 + + def get(self, error: NotFound): + return "replace me with a template, 404 not found", 404 diff --git a/pysite/views/error_handlers/http_5xx.py b/pysite/views/error_handlers/http_5xx.py new file mode 100644 index 00000000..ed4d8d82 --- /dev/null +++ b/pysite/views/error_handlers/http_5xx.py @@ -0,0 +1,12 @@ +# coding=utf-8 +from werkzeug.exceptions import HTTPException + +from pysite.base_route import ErrorView + + +class Error404View(ErrorView): + name = "error_5xx" + error_code = range(500, 600) + + def get(self, error: HTTPException): + return "Internal server error. Please try again later!", error.code diff --git a/pysite/views/main/error_handlers/__init__.py b/pysite/views/main/error_handlers/__init__.py deleted file mode 100644 index 9bad5790..00000000 --- a/pysite/views/main/error_handlers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# coding=utf-8 diff --git a/pysite/views/main/error_handlers/http_404.py b/pysite/views/main/error_handlers/http_404.py deleted file mode 100644 index 1d557d9b..00000000 --- a/pysite/views/main/error_handlers/http_404.py +++ /dev/null @@ -1,12 +0,0 @@ -# coding=utf-8 -from werkzeug.exceptions import NotFound - -from pysite.base_route import ErrorView - - -class Error404View(ErrorView): - name = "error_404" - error_code = 404 - - def get(self, error: NotFound): - return "replace me with a template, 404 not found", 404 diff --git a/pysite/views/main/error_handlers/http_5xx.py b/pysite/views/main/error_handlers/http_5xx.py deleted file mode 100644 index ed4d8d82..00000000 --- a/pysite/views/main/error_handlers/http_5xx.py +++ /dev/null @@ -1,12 +0,0 @@ -# coding=utf-8 -from werkzeug.exceptions import HTTPException - -from pysite.base_route import ErrorView - - -class Error404View(ErrorView): - name = "error_5xx" - error_code = range(500, 600) - - def get(self, error: HTTPException): - return "Internal server error. Please try again later!", error.code diff --git a/pysite/views/main/index.py b/pysite/views/main/index.py index 0c2d1578..210eb057 100644 --- a/pysite/views/main/index.py +++ b/pysite/views/main/index.py @@ -7,4 +7,4 @@ class IndexView(RouteView): name = "index" def get(self): - return self.render("index.html") + return self.render("main/index.html") diff --git a/pysite/views/main/ws_test.py b/pysite/views/main/ws_test.py index c28269a8..c53515c5 100644 --- a/pysite/views/main/ws_test.py +++ b/pysite/views/main/ws_test.py @@ -10,6 +10,6 @@ class WSTest(RouteView): def get(self): return self.render( - "ws_test.html", + "main/ws_test.html", server_name=os.environ.get("SERVER_NAME", "localhost") ) diff --git a/pysite/views/staff/index.py b/pysite/views/staff/index.py index c23af392..19e89333 100644 --- a/pysite/views/staff/index.py +++ b/pysite/views/staff/index.py @@ -7,4 +7,4 @@ class StaffView(RouteView): name = "staff" def get(self): - return self.render("staff.html") + return self.render("staff/staff.html") diff --git a/templates/base.html b/templates/base.html deleted file mode 100644 index 5dd0c02c..00000000 --- a/templates/base.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - {% block head %} - Python | {% block title %}{% endblock %} - - - - - - - {% endblock %} - - -{% include "navigation.html" %} -{% block content %}{% endblock %} - - diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index 418347d2..00000000 --- a/templates/index.html +++ /dev/null @@ -1,9 +0,0 @@ -{% extends "base.html" %} -{% block title %}Home{% endblock %} -{% block content %} -
-

- Coming soon :tm: -

-
-{% endblock %} \ No newline at end of file diff --git a/templates/main/base.html b/templates/main/base.html new file mode 100644 index 00000000..5dd0c02c --- /dev/null +++ b/templates/main/base.html @@ -0,0 +1,18 @@ + + + + {% block head %} + Python | {% block title %}{% endblock %} + + + + + + + {% endblock %} + + +{% include "navigation.html" %} +{% block content %}{% endblock %} + + diff --git a/templates/main/index.html b/templates/main/index.html new file mode 100644 index 00000000..418347d2 --- /dev/null +++ b/templates/main/index.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} +{% block title %}Home{% endblock %} +{% block content %} +
+

+ Coming soon :tm: +

+
+{% endblock %} \ No newline at end of file diff --git a/templates/main/navigation.html b/templates/main/navigation.html new file mode 100644 index 00000000..cbd6a36a --- /dev/null +++ b/templates/main/navigation.html @@ -0,0 +1,19 @@ +
+ +
\ No newline at end of file diff --git a/templates/main/ws_test.html b/templates/main/ws_test.html new file mode 100644 index 00000000..6ef1bb68 --- /dev/null +++ b/templates/main/ws_test.html @@ -0,0 +1,24 @@ +{% extends "base.html" %} +{% block title %}WS Test{% endblock %} +{% block content %} +
+

Open your JS console to test

+ + +
+{% endblock %} diff --git a/templates/navigation.html b/templates/navigation.html deleted file mode 100644 index cbd6a36a..00000000 --- a/templates/navigation.html +++ /dev/null @@ -1,19 +0,0 @@ -
- -
\ No newline at end of file diff --git a/templates/staff.html b/templates/staff.html deleted file mode 100644 index 3017f65c..00000000 --- a/templates/staff.html +++ /dev/null @@ -1,9 +0,0 @@ -{% extends "base.html" %} -{% block title %}Home{% endblock %} -{% block content %} -
-

- This will be for staff only. Login required. -

-
-{% endblock %} \ No newline at end of file diff --git a/templates/staff/staff.html b/templates/staff/staff.html new file mode 100644 index 00000000..3017f65c --- /dev/null +++ b/templates/staff/staff.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} +{% block title %}Home{% endblock %} +{% block content %} +
+

+ This will be for staff only. Login required. +

+
+{% endblock %} \ No newline at end of file diff --git a/templates/ws_test.html b/templates/ws_test.html deleted file mode 100644 index 6ef1bb68..00000000 --- a/templates/ws_test.html +++ /dev/null @@ -1,24 +0,0 @@ -{% extends "base.html" %} -{% block title %}WS Test{% endblock %} -{% block content %} -
-

Open your JS console to test

- - -
-{% endblock %} -- cgit v1.2.3