From f2700ecd90522df1d42725791bca6229b6bd3f37 Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Mon, 6 Dec 2021 13:44:40 +0000 Subject: [PATCH] Added correct answer view --- ref-test/admin/views.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ref-test/admin/views.py b/ref-test/admin/views.py index 78752a4..54a4108 100644 --- a/ref-test/admin/views.py +++ b/ref-test/admin/views.py @@ -14,7 +14,7 @@ from uuid import uuid4 import secrets from datetime import datetime, date from .models.tests import Test -from common.data_tools import get_default_dataset, get_time_options, available_datasets, get_datasets +from common.data_tools import get_default_dataset, get_time_options, available_datasets, get_datasets, get_correct_answers views = Blueprint( 'admin_views', @@ -452,12 +452,20 @@ def view_entries(): @admin_account_required @login_required def view_entry(_id=''): - from main import db + from main import app, db entry = decrypt_find_one(db.entries, {'_id': _id}) if request.method == 'GET': if not entry: return abort(404) - return render_template('/admin/result-detail.html', entry = entry) + test_code = entry['test_code'] + test = db.tests.find_one({'test_code' : test_code}) + dataset = test['dataset'] + dataset_path = os.path.join(app.config['DATA_FILE_DIRECTORY'], dataset) + with open(dataset_path, 'r') as _dataset: + data = loads(_dataset.read()) + correct = get_correct_answers(dataset=data) + print(correct.values()) + return render_template('/admin/result-detail.html', entry = entry, correct = correct) if request.method == 'POST': if not entry: return jsonify({'error': 'A valid entry could no be found.'}), 404