diff options
author | 2018-03-29 22:39:07 +0100 | |
---|---|---|
committer | 2018-03-29 22:39:07 +0100 | |
commit | 430b5d23a82e81add12fce46a2e8e67ac6cfb7db (patch) | |
tree | a0cf9eb8f76cbe57e5da3ee5d35da79bb6bbbdea | |
parent | Fix error routing and more work on static files (diff) |
More convenient static_file() function for templates
-rw-r--r-- | pysite/base_route.py | 6 | ||||
-rw-r--r-- | pysite/route_manager.py | 1 | ||||
-rw-r--r-- | templates/errors/error.html | 6 | ||||
-rw-r--r-- | templates/main/base.html | 6 | ||||
-rw-r--r-- | templates/main/countdown.html | 22 | ||||
-rw-r--r-- | templates/main/navigation.html | 2 |
6 files changed, 12 insertions, 31 deletions
diff --git a/pysite/base_route.py b/pysite/base_route.py index d63abaa6..c7d58f49 100644 --- a/pysite/base_route.py +++ b/pysite/base_route.py @@ -2,7 +2,7 @@ from collections import Iterable from typing import Any -from flask import Blueprint, Response, jsonify, render_template +from flask import Blueprint, Response, jsonify, render_template, url_for from flask.views import MethodView from werkzeug.exceptions import default_exceptions @@ -31,9 +31,13 @@ class BaseView(MethodView, OauthMixin): context["view"] = self context["logged_in"] = self.logged_in context["login_url"] = DISCORD_OAUTH_REDIRECT + context["static_file"] = self._static_file return render_template(template_names, **context) + def _static_file(self, filename): + return url_for("static", filename=filename) + class RouteView(BaseView): """ diff --git a/pysite/route_manager.py b/pysite/route_manager.py index 488c596f..f8bd705b 100644 --- a/pysite/route_manager.py +++ b/pysite/route_manager.py @@ -71,7 +71,6 @@ class RouteManager: self.app.register_blueprint(sub_blueprint) except Exception: logging.getLogger(__name__).exception(f"Failed to register blueprint for subdomain: {sub}") - # exit(1) # Load the websockets self.ws_blueprint = Blueprint("ws", __name__) diff --git a/templates/errors/error.html b/templates/errors/error.html index 6aeaee02..366bd49e 100644 --- a/templates/errors/error.html +++ b/templates/errors/error.html @@ -5,7 +5,7 @@ {% block beta_error %}{% endblock %} {% block extra_head %} - <link href="{{ url_for('static', filename='css/window.css') }}" rel="stylesheet" type="text/css"/> + <link href="{{ static_file('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="{{ url_for('static', filename='js/typewriter.js') }}" type="application/javascript"></script> - <script src="{{ url_for('static', filename='js/500.js') }}" type="application/javascript"></script> + <script src="{{ static_file('js/typewriter.js') }}" type="application/javascript"></script> + <script src="{{ static_file('js/500.js') }}" type="application/javascript"></script> {% endblock %} {% block content %} diff --git a/templates/main/base.html b/templates/main/base.html index 7e278a09..d5391791 100644 --- a/templates/main/base.html +++ b/templates/main/base.html @@ -7,9 +7,9 @@ <meta name="viewport" content="width=device-width, initial-scale=1"> <script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.39/js/uikit.min.js"></script> - <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}"> - <link rel="stylesheet" href="{{ url_for('static', filename='uikit_blurple.css') }}"/> - <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"/> + <link rel="shortcut icon" href="{{ static_file('favicon.ico') }}"> + <link rel="stylesheet" href="{{ static_file('uikit_blurple.css') }}"/> + <link rel="stylesheet" href="{{ static_file('style.css') }}"/> <!-- OpenGraph metadata --> <meta property="og:title" content="Python Discord | {% block og_title %}{% endblock %}"> diff --git a/templates/main/countdown.html b/templates/main/countdown.html deleted file mode 100644 index 8dd25564..00000000 --- a/templates/main/countdown.html +++ /dev/null @@ -1,22 +0,0 @@ -{% extends "main/base.html" %} -{% block title %}Countdown{% endblock %} -{% block og_title %}Countdown{% endblock %} -{% block og_description %}Countdown for Code Jams.{% endblock %} -{% block beta_error %}{% endblock %} -{% block content %} -<div class="uk-section-primary"> - - - - -<div class="uk-container uk-align-center"> - <h1 id="countdown-title" class="uk-heading-primary uk-text-center">Code Jam Countdown</h1> -<div class="uk-text-center"> - <h1 id="remaining"></h1> -</div> -</div> -</div> - - -<script src="/static/js/countdown.js"></script> -{% endblock %}
\ No newline at end of file diff --git a/templates/main/navigation.html b/templates/main/navigation.html index ca196a81..53bdf196 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="{{ url_for('static', filename='logos/logo_banner.png') }}" class="navbar-logo"/> + <img src="{{ static_file('logos/logo_banner.png') }}" class="navbar-logo"/> </a> </div> |