Added correct answer view
This commit is contained in:
parent
03d419c3fc
commit
acfcca13b3
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user