Added correct answer view
This commit is contained in:
parent
41a7129959
commit
3d03fb79a7
@ -14,7 +14,7 @@ from uuid import uuid4
|
|||||||
import secrets
|
import secrets
|
||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
from .models.tests import Test
|
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(
|
views = Blueprint(
|
||||||
'admin_views',
|
'admin_views',
|
||||||
@ -452,12 +452,20 @@ def view_entries():
|
|||||||
@admin_account_required
|
@admin_account_required
|
||||||
@login_required
|
@login_required
|
||||||
def view_entry(_id=''):
|
def view_entry(_id=''):
|
||||||
from main import db
|
from main import app, db
|
||||||
entry = decrypt_find_one(db.entries, {'_id': _id})
|
entry = decrypt_find_one(db.entries, {'_id': _id})
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
if not entry:
|
if not entry:
|
||||||
return abort(404)
|
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 request.method == 'POST':
|
||||||
if not entry:
|
if not entry:
|
||||||
return jsonify({'error': 'A valid entry could no be found.'}), 404
|
return jsonify({'error': 'A valid entry could no be found.'}), 404
|
||||||
|
Loading…
Reference in New Issue
Block a user