wanderhome-quiz/server/app/views.py

27 lines
736 B
Python
Raw Normal View History

2022-08-29 17:09:07 +01:00
from .tools.data import check_file, load
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-24 15:55:53 +01:00
from flask.helpers import abort
views = Blueprint(
name='views',
import_name=__name__
)
@views.route('/fetch/<string:data_type>/')
def _fetch(data_type):
if not check_file(f'{data_type}.json'): return abort(404)
if data_type == 'questions': return render_questions()
return load(f'{data_type}.json')
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)
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