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 from .site_info import site_meta, page_info views = Blueprint('views', __name__) @views.route('/compatibility') def compatibility(): return render_template( 'compatibility.html', site_meta = site_meta, page_info = page_info['compatibility'] ) @views.route('/') def home(): return render_template( 'home.html', site_meta = site_meta, page_info = page_info['home'] ) @views.route('/masks') def about(): return render_template( 'masks.html', site_meta = site_meta, page_info = page_info['masks'] ) @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', 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', site_meta = site_meta, page_info = page_info['results'], results = results, playbooks = playbooks, labels = labels, sources = sources ) @views.route('/reset') def reset(): session.clear() return redirect(url_for('views.quiz'))