masks-personality-quiz/interface/views.py

70 lines
1.8 KiB
Python
Raw Permalink Normal View History

2021-11-01 13:58:15 +00:00
from flask import Blueprint, render_template, request, session, redirect
from flask.helpers import url_for
from data.labels import labels
from data.playbooks import playbooks
from data.questions import questions
from data.sources import sources
from quiz.validators import validate_submissions
from quiz.evaluation import evaluate_quiz
2021-11-03 12:37:18 +00:00
from .site_info import site_meta, page_info
2021-11-01 13:58:15 +00:00
views = Blueprint('views', __name__)
@views.route('/compatibility')
def compatibility():
2021-11-03 12:37:18 +00:00
return render_template(
'compatibility.html',
site_meta = site_meta,
page_info = page_info['compatibility']
)
2021-11-01 13:58:15 +00:00
@views.route('/')
def home():
2021-11-03 12:37:18 +00:00
return render_template(
'home.html',
site_meta = site_meta,
page_info = page_info['home']
)
2021-11-01 13:58:15 +00:00
@views.route('/masks')
def about():
2021-11-03 12:37:18 +00:00
return render_template(
'masks.html',
site_meta = site_meta,
page_info = page_info['masks']
)
2021-11-01 13:58:15 +00:00
@views.route('/quiz', methods=['GET', 'POST'])
def quiz():
if request.method == 'POST':
session['submission'] = request.form
if validate_submissions(session['submission']):
return redirect(url_for('views.results'))
2021-11-03 12:37:18 +00:00
return render_template(
'quiz.html',
site_meta = site_meta,
page_info = page_info['quiz'],
questions=questions,
sources=sources
)
2021-11-01 13:58:15 +00:00
@views.route('/results')
def results():
if 'submission' not in session:
return redirect(url_for('views.quiz'))
results = evaluate_quiz(session['submission'])
2021-11-03 12:37:18 +00:00
return render_template(
'results.html',
site_meta = site_meta,
page_info = page_info['results'],
results = results,
playbooks = playbooks,
labels = labels,
sources = sources
)
2021-11-01 13:58:15 +00:00
@views.route('/reset')
def reset():
session.clear()
return redirect(url_for('views.quiz'))