From 011b4e06dd0f18e46868a7395fd3406271e26bf3 Mon Sep 17 00:00:00 2001 From: Vivek Santayana Date: Wed, 3 Nov 2021 12:37:18 +0000 Subject: [PATCH] Bug fixes for dynamic meta tags --- interface/error_handlers.py | 7 ++++- interface/site_info.py | 40 ++++++++++++++++++++++++++ interface/templates/404.html | 23 +++++++++++++-- interface/templates/base.html | 6 ++-- interface/templates/compatibility.html | 1 - interface/templates/dev.html | 23 --------------- interface/templates/home.html | 3 +- interface/templates/masks.html | 1 - interface/templates/og-meta.html | 13 +++++---- interface/templates/quiz.html | 1 - interface/templates/results.html | 1 - interface/views.py | 37 ++++++++++++++++++++---- 12 files changed, 110 insertions(+), 46 deletions(-) create mode 100644 interface/site_info.py delete mode 100644 interface/templates/dev.html diff --git a/interface/error_handlers.py b/interface/error_handlers.py index 4454e4c..5e01949 100644 --- a/interface/error_handlers.py +++ b/interface/error_handlers.py @@ -1,7 +1,12 @@ from flask import render_template, Blueprint, request +from .site_info import site_meta, page_info error_handler = Blueprint('error_handlers', __name__) @error_handler.app_errorhandler(404) def not_found(e): - return render_template("404.html") \ No newline at end of file + return render_template( + "404.html", + site_meta = site_meta, + page_info = page_info['404'] + ) \ No newline at end of file diff --git a/interface/site_info.py b/interface/site_info.py new file mode 100644 index 0000000..8856f00 --- /dev/null +++ b/interface/site_info.py @@ -0,0 +1,40 @@ +site_meta = { + 'title': 'Which Masks Playbook Are You? — a Personality Quiz', + 'name': 'Masks Personality Quiz | V.S.', + 'description': 'A personality quiz to find out which Masks playbook you are.', + 'locale': 'en_GB', + 'theme_colour': '#343a40' +} + +page_info = { + 'home': { + 'url': '/', + 'template': 'home.html', + 'title': 'Home' + }, + 'compatibility': { + 'url': '/compatibility', + 'template': 'compatibility.html', + 'title': 'Compatibility and Accessibility' + }, + 'masks': { + 'url': '/masks', + 'template': 'masks.html', + 'title': 'About Masks' + }, + 'quiz': { + 'url': '/quiz', + 'template': 'quiz.html', + 'title': 'Take the Quiz' + }, + 'results': { + 'url': '/results', + 'template': 'results.html', + 'title': 'Your Results' + }, + '404': { + 'url': '/', + 'template': '404.html', + 'title': 'Page Not Found' + }, +} \ No newline at end of file diff --git a/interface/templates/404.html b/interface/templates/404.html index 127bbd2..a8ea795 100644 --- a/interface/templates/404.html +++ b/interface/templates/404.html @@ -1,11 +1,28 @@ {% extends "base.html" %} -{% block title %} Page Not Found {% endblock %} +{% block meta %} + + + + + + + + + + + + + + + + + + +{% endblock %} {% block content %} -

Error: Page Not Found

Return to the Home Page
- {% endblock %} \ No newline at end of file diff --git a/interface/templates/base.html b/interface/templates/base.html index 2389dc0..c798f9b 100644 --- a/interface/templates/base.html +++ b/interface/templates/base.html @@ -23,9 +23,11 @@ - {% block title %}{% endblock %} | Which Masks Playbook Are You? — a Personality Quiz + {{ page_info['title']|safe }} | {{ site_meta['title']|safe }} - {% include "og-meta.html" %} + {% block meta %} + {% include "og-meta.html" %} + {% endblock %} diff --git a/interface/templates/compatibility.html b/interface/templates/compatibility.html index 1a7f9d6..5f5485f 100644 --- a/interface/templates/compatibility.html +++ b/interface/templates/compatibility.html @@ -1,5 +1,4 @@ {% extends "base.html" %} -{% block title %} Compatibility and Accessibility {% endblock %} {% block content %}

Compatibility and Accessibility

diff --git a/interface/templates/dev.html b/interface/templates/dev.html deleted file mode 100644 index 7d94f8c..0000000 --- a/interface/templates/dev.html +++ /dev/null @@ -1,23 +0,0 @@ -{% extends "base.html" %} -{% block title %} Development {% endblock %} -{% block content %} -

Development

-

- I started work on the first version of this personality quiz over a year ago, when I decided to teach myself programming. The original version ran on JavaScript and was rendered and evaluated entirely by the browser. This version runs entirely on the server, and the quiz results are evaluated by the server rather than the client. -

-

- The back-end runs on Python 3.10, using the Flask framework. The web pages are templated using Jinja. The web site is rendered using html and the Bootstrap CSS framework. There have been some elements of the interface enhanced using rudimentary JavaScript, including the jQuery library. Of all of these programming languages, Python has proved to be a far more intuitive language to learn, and generally programming this has been a lot more enjoyable and a lot less frustrating than the earlier iteration that used JavaScript. -

-

- The quiz runs by rendering a form with all of the questions and options on the browser. The browser then submits the responses via a POST request to the server. The server evaluates the responses and renders the results accordingly. There is no information stored on the client. -

-

- All data transacted between the client and the server is stored as a Flask session for the duration that the user is on the web site. If the user closes the site, the session data is deleted and all answers submitted are lost. -

-

- There are, of course, some considerable inefficiencies in the way I have set up the templating. I have written the text for all the various web pages in the templates of the respective pages. Ideally, I would have preferred having a single template for all of the web pages or views, and then have the content served on those pages render dynamically based on the URL query. But that was a level of programming that was gratuitous at this point, as really most of the pages were serving static content anyway so it did not matter just now. -

-

- In addition, this is the first time I am storing the code of the quiz on my Git repo, and having a much more streamlined version control process. -

-{% endblock %} \ No newline at end of file diff --git a/interface/templates/home.html b/interface/templates/home.html index 018a681..5819041 100644 --- a/interface/templates/home.html +++ b/interface/templates/home.html @@ -1,7 +1,6 @@ {% extends "base.html" %} -{% block title %} Home | Which Masks Playbook Are You? — a Personality Quiz {% endblock %} {% block content %} -

Home page

+

Home Page

Background

diff --git a/interface/templates/masks.html b/interface/templates/masks.html index 1d2aca4..dfcd79d 100644 --- a/interface/templates/masks.html +++ b/interface/templates/masks.html @@ -1,5 +1,4 @@ {% extends "base.html" %} -{% block title %} About Masks {% endblock %} {% block content %}

About Masks

Masks is a game by Brendan Conway using the Powered by the Apocalypse engine. For those unfamiliar with the term, Powered by the Apocalypse is a category of game systems that are based on the overall structure of the Apocalypse World system by Vincent and Meguey Baker. The core concept behind this system is to encourage collaborate and improvisational story-telling by streamlining the mechanics. This is in sharp contrast to traditional TRPGs that have very granular rules and hierarchical authority between a Game Master and the players.

diff --git a/interface/templates/og-meta.html b/interface/templates/og-meta.html index 2d2270e..52cc767 100644 --- a/interface/templates/og-meta.html +++ b/interface/templates/og-meta.html @@ -1,16 +1,17 @@ - - + + - + - + + - - + + diff --git a/interface/templates/quiz.html b/interface/templates/quiz.html index f1901cb..1930797 100644 --- a/interface/templates/quiz.html +++ b/interface/templates/quiz.html @@ -1,5 +1,4 @@ {% extends "base.html" %} -{% block title %} Take the Quiz {% endblock %} {% block content %}

Take the Quiz

diff --git a/interface/templates/results.html b/interface/templates/results.html index 8d56d48..c09d9b3 100644 --- a/interface/templates/results.html +++ b/interface/templates/results.html @@ -1,5 +1,4 @@ {% extends "base.html" %} -{% block title %} Your Results {% endblock %} {% block content %}

Your Results

diff --git a/interface/views.py b/interface/views.py index 9962182..cb8af7c 100644 --- a/interface/views.py +++ b/interface/views.py @@ -6,20 +6,33 @@ from data.questions import questions from data.sources import sources from quiz.validators import validate_submissions from quiz.evaluation import evaluate_quiz +from .site_info import site_meta, page_info views = Blueprint('views', __name__) @views.route('/compatibility') def compatibility(): - return render_template('compatibility.html') + return render_template( + 'compatibility.html', + site_meta = site_meta, + page_info = page_info['compatibility'] + ) @views.route('/') def home(): - return render_template('home.html') + return render_template( + 'home.html', + site_meta = site_meta, + page_info = page_info['home'] + ) @views.route('/masks') def about(): - return render_template('masks.html') + return render_template( + 'masks.html', + site_meta = site_meta, + page_info = page_info['masks'] + ) @views.route('/quiz', methods=['GET', 'POST']) def quiz(): @@ -27,14 +40,28 @@ def quiz(): session['submission'] = request.form if validate_submissions(session['submission']): return redirect(url_for('views.results')) - return render_template('quiz.html', questions=questions, sources=sources) + return render_template( + 'quiz.html', + site_meta = site_meta, + page_info = page_info['quiz'], + questions=questions, + sources=sources + ) @views.route('/results') def results(): if 'submission' not in session: return redirect(url_for('views.quiz')) results = evaluate_quiz(session['submission']) - return render_template('results.html', results = results, playbooks = playbooks, labels = labels, sources = sources) + return render_template( + 'results.html', + site_meta = site_meta, + page_info = page_info['results'], + results = results, + playbooks = playbooks, + labels = labels, + sources = sources + ) @views.route('/reset') def reset():