masks-personality-quiz/interface/views.py

43 lines
1.3 KiB
Python
Raw 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
views = Blueprint('views', __name__)
@views.route('/compatibility')
def compatibility():
return render_template('compatibility.html')
@views.route('/')
def home():
return render_template('home.html')
@views.route('/masks')
def about():
return render_template('masks.html')
@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'))
return render_template('quiz.html', 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)
@views.route('/reset')
def reset():
session.clear()
return redirect(url_for('views.quiz'))