Added get_file method to datasets
This commit is contained in:
parent
c9ad8e87cd
commit
9a02048199
@ -435,10 +435,7 @@ def _view_entry(id:str=None):
|
|||||||
flash('Invalid entry ID.', 'error')
|
flash('Invalid entry ID.', 'error')
|
||||||
return redirect(url_for('admin._view_entries'))
|
return redirect(url_for('admin._view_entries'))
|
||||||
test = entry.test
|
test = entry.test
|
||||||
dataset = test.dataset
|
data = test.dataset.get_data()
|
||||||
dataset_path = dataset.get_file()
|
|
||||||
with open(dataset_path, 'r') as _dataset:
|
|
||||||
data = loads(_dataset.read())
|
|
||||||
correct = get_correct_answers(dataset=data)
|
correct = get_correct_answers(dataset=data)
|
||||||
answers = answer_options(dataset=data)
|
answers = answer_options(dataset=data)
|
||||||
return render_template('/admin/result-detail.html', entry = entry, correct = correct, answers = answers)
|
return render_template('/admin/result-detail.html', entry = entry, correct = correct, answers = answers)
|
||||||
|
@ -8,7 +8,7 @@ from flask_login import current_user
|
|||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from json import dump
|
from json import dump, loads
|
||||||
from os import path, remove
|
from os import path, remove
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
@ -116,6 +116,12 @@ class Dataset(db.Model):
|
|||||||
file_path = path.join(data, 'questions', filename)
|
file_path = path.join(data, 'questions', filename)
|
||||||
return file_path
|
return file_path
|
||||||
|
|
||||||
|
def get_data(self):
|
||||||
|
dataset_path = self.get_file()
|
||||||
|
with open(dataset_path, 'r') as _dataset:
|
||||||
|
data = loads(_dataset.read())
|
||||||
|
return data
|
||||||
|
|
||||||
def update(self, data:list=None, default:bool=False):
|
def update(self, data:list=None, default:bool=False):
|
||||||
self.date = datetime.now()
|
self.date = datetime.now()
|
||||||
if default: self.make_default()
|
if default: self.make_default()
|
||||||
|
Loading…
Reference in New Issue
Block a user