diff options
author | 2018-03-29 16:41:05 +0100 | |
---|---|---|
committer | 2018-03-29 16:41:05 +0100 | |
commit | 24c7be0894d459c06862c3de6d3c038f517b44e5 (patch) | |
tree | 78711d55c543ebc5d7f0d04a602085711a325505 | |
parent | fixes path to static files in subdomains (#46) (diff) |
Fix error routing and more work on static files
-rw-r--r-- | pysite/base_route.py | 15 | ||||
-rw-r--r-- | pysite/route_manager.py | 4 | ||||
-rw-r--r-- | pysite/views/api/error_view.py | 4 | ||||
-rw-r--r-- | templates/errors/error.html | 6 | ||||
-rw-r--r-- | templates/main/navigation.html | 2 |
5 files changed, 15 insertions, 16 deletions
diff --git a/pysite/base_route.py b/pysite/base_route.py index 3bc04728..d63abaa6 100644 --- a/pysite/base_route.py +++ b/pysite/base_route.py @@ -4,6 +4,7 @@ from typing import Any from flask import Blueprint, Response, jsonify, render_template from flask.views import MethodView +from werkzeug.exceptions import default_exceptions from pysite.constants import DISCORD_OAUTH_REDIRECT, ErrorCodes from pysite.mixins import OauthMixin @@ -171,12 +172,12 @@ class ErrorView(BaseView): if isinstance(cls.error_code, Iterable): for code in cls.error_code: - try: - if cls.register_on_app: - manager.app.errorhandler(code)(cls.as_view(cls.name)) - else: - blueprint.errorhandler(code)(cls.as_view(cls.name)) - except KeyError: # This happens if we try to register a handler for a HTTP code that doesn't exist - pass + if isinstance(code, int) and code not in default_exceptions: + continue # Otherwise we'll possibly get an exception thrown during blueprint registration + + if cls.register_on_app: + manager.app.errorhandler(code)(cls.as_view(cls.name)) + else: + blueprint.errorhandler(code)(cls.as_view(cls.name)) else: raise RuntimeError("Error views must have an `error_code` that is either an `int` or an iterable") # pragma: no cover # noqa: E501 diff --git a/pysite/route_manager.py b/pysite/route_manager.py index 949d4ed9..488c596f 100644 --- a/pysite/route_manager.py +++ b/pysite/route_manager.py @@ -66,12 +66,12 @@ class RouteManager: for sub in self.subdomains: sub_blueprint = Blueprint(sub, __name__, subdomain=sub) self.log.debug(f"Loading Blueprint: {sub_blueprint.name}") + self.load_views(sub_blueprint, f"pysite/views/{sub}") try: self.app.register_blueprint(sub_blueprint) except Exception: logging.getLogger(__name__).exception(f"Failed to register blueprint for subdomain: {sub}") - else: - self.load_views(sub_blueprint, f"pysite/views/{sub}") + # exit(1) # Load the websockets self.ws_blueprint = Blueprint("ws", __name__) diff --git a/pysite/views/api/error_view.py b/pysite/views/api/error_view.py index 6d278604..30e133f9 100644 --- a/pysite/views/api/error_view.py +++ b/pysite/views/api/error_view.py @@ -1,7 +1,5 @@ # coding=utf-8 -from collections import Iterable - -from flask import jsonify, Blueprint +from flask import jsonify from werkzeug.exceptions import HTTPException from pysite.base_route import ErrorView diff --git a/templates/errors/error.html b/templates/errors/error.html index 13ff98db..6aeaee02 100644 --- a/templates/errors/error.html +++ b/templates/errors/error.html @@ -5,7 +5,7 @@ {% block beta_error %}{% endblock %} {% block extra_head %} - <link href="/static/css/window.css" rel="stylesheet" type="text/css"/> + <link href="{{ url_for('static', filename='css/window.css') }}" rel="stylesheet" type="text/css"/> <script> window._RequestMethod = "{{ request.method.lower() }}"; @@ -14,8 +14,8 @@ window._Path = "{{ request.path }}"; </script> - <script src="/static/js/typewriter.js" type="application/javascript"></script> - <script src="/static/js/500.js" type="application/javascript"></script> + <script src="{{ url_for('static', filename='js/typewriter.js') }}" type="application/javascript"></script> + <script src="{{ url_for('static', filename='js/500.js') }}" type="application/javascript"></script> {% endblock %} {% block content %} diff --git a/templates/main/navigation.html b/templates/main/navigation.html index ec5cfafb..ca196a81 100644 --- a/templates/main/navigation.html +++ b/templates/main/navigation.html @@ -7,7 +7,7 @@ <nav data-uk-navbar class="uk-navbar-container uk-navbar-transparent" uk-navbar="boundary-align: true"> <div class="uk-navbar-left uk-padding-remove-left"> <a href="/" class="uk-navbar-item uk-logo uk-padding-remove-left"> - <img src="/static/logos/logo_banner.png" class="navbar-logo"/> + <img src="{{ url_for('static', filename='logos/logo_banner.png') }}" class="navbar-logo"/> </a> </div> |