Updated json structure validation
Only works with the data list File parsed in the View layer
This commit is contained in:
parent
26a6b45d75
commit
2b2a6ddd25
@ -18,12 +18,10 @@ def check_is_json(file):
|
||||
if not '.' in file.filename or not file.filename.rsplit('.',1)[-1] == 'json': return False
|
||||
return True
|
||||
|
||||
def validate_json(file):
|
||||
file.stream.seek(0)
|
||||
data = json.loads(file.read())
|
||||
def validate_json(data):
|
||||
if not isinstance(data, list): return False
|
||||
for block in data:
|
||||
block_type = block.pop('type', None)
|
||||
block_type = block.get('type', None)
|
||||
if block_type not in ['block', 'question']: return False
|
||||
if block_type == 'question':
|
||||
if not all (key in block for key in ['q_no', 'text', 'options', 'correct', 'q_type', 'tags']): return False
|
||||
|
Loading…
Reference in New Issue
Block a user