wanderhome-quiz/server/app/views.py

28 lines
651 B
Python

from .models import Entry
from .tools.data import load
from .tools.quiz import compile_results, evaluate_answers, render_questions
from flask import Blueprint, jsonify, request
views = Blueprint(
name='views',
import_name=__name__
)
@views.route('/questions/')
def _questions():
return render_questions()
@views.route('/submit/', methods=['POST'])
def _submit():
answers = request.json
scores = evaluate_answers(answers)
results = compile_results(results=scores)
new_entry = Entry(answers=answers, results=results)
new_entry.add()
return jsonify(results)
@views.route('/results/')
def _results():
pass