2022-08-31 01:19:15 +01:00
|
|
|
from .models import Entry
|
2022-08-31 14:50:02 +01:00
|
|
|
from .tools.data import load
|
2022-08-29 17:09:07 +01:00
|
|
|
from .tools.quiz import compile_results, evaluate_answers, render_questions
|
2022-08-24 15:55:53 +01:00
|
|
|
|
2022-08-29 17:09:07 +01:00
|
|
|
from flask import Blueprint, jsonify, request
|
2022-08-31 14:50:02 +01:00
|
|
|
|
2022-08-24 15:55:53 +01:00
|
|
|
|
|
|
|
views = Blueprint(
|
|
|
|
name='views',
|
|
|
|
import_name=__name__
|
|
|
|
)
|
|
|
|
|
2022-08-31 00:48:13 +01:00
|
|
|
@views.route('/questions/')
|
|
|
|
def _questions():
|
|
|
|
return render_questions()
|
2022-08-24 15:55:53 +01:00
|
|
|
|
2022-08-29 17:09:07 +01:00
|
|
|
@views.route('/submit/', methods=['POST'])
|
2022-08-24 15:55:53 +01:00
|
|
|
def _submit():
|
2022-08-29 17:09:07 +01:00
|
|
|
answers = request.json
|
|
|
|
scores = evaluate_answers(answers)
|
|
|
|
results = compile_results(results=scores)
|
2022-08-31 01:19:15 +01:00
|
|
|
new_entry = Entry(answers=answers, results=results)
|
|
|
|
new_entry.add()
|
2022-08-29 17:09:07 +01:00
|
|
|
return jsonify(results)
|
2022-08-24 15:55:53 +01:00
|
|
|
|
2022-08-29 17:09:07 +01:00
|
|
|
@views.route('/results/')
|
2022-08-24 15:55:53 +01:00
|
|
|
def _results():
|
|
|
|
pass
|