Added decorator to test availability of datasets
Used decorator tool to validate dataset exists on views
This commit is contained in:
@ -1,8 +1,13 @@
|
||||
from ..models import Dataset
|
||||
|
||||
from flask import current_app as app
|
||||
from flask import flash, redirect
|
||||
from flask.helpers import url_for
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from random import shuffle
|
||||
from functools import wraps
|
||||
|
||||
def load(filename:str):
|
||||
data_dir = Path(app.config.get('DATA'))
|
||||
@ -66,4 +71,14 @@ def get_tag_list(dataset:list):
|
||||
if block['type'] == 'question': output = list(set(output) | set(block['tags']))
|
||||
if block['type'] == 'block':
|
||||
for question in block['questions']: output = list(set(output) | set(question['tags']))
|
||||
return output
|
||||
return output
|
||||
|
||||
def check_dataset_exists(function):
|
||||
@wraps(function)
|
||||
def wrapper(*args, **kwargs):
|
||||
datasets = Dataset.query.all()
|
||||
if not datasets:
|
||||
flash('There are no available question datasets. Please upload a question dataset first, or use the question editor to create a new dataset.', 'error')
|
||||
return redirect(url_for('admin._questions'))
|
||||
return function(*args, **kwargs)
|
||||
return wrapper
|
Reference in New Issue
Block a user