Commit
·
750ccee
1
Parent(s):
0e75969
update_
Browse files
main.py
CHANGED
@@ -249,16 +249,37 @@ def compute_marks():
|
|
249 |
|
250 |
# Add validation for answers
|
251 |
def validate_answers(answers):
|
252 |
-
|
253 |
-
|
254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
return False
|
256 |
-
return True
|
257 |
|
258 |
if not validate_answers(answers):
|
259 |
log_print("Invalid answer format", "ERROR")
|
|
|
260 |
return jsonify({"error": "Invalid answer format"}), 400
|
261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
# Initialize data structure and parent folder
|
263 |
data = {}
|
264 |
parent_folder = ans_image_dir # Use the temp directory path defined earlier
|
|
|
249 |
|
250 |
# Add validation for answers
|
251 |
def validate_answers(answers):
|
252 |
+
try:
|
253 |
+
if not isinstance(answers, list):
|
254 |
+
return False
|
255 |
+
# Check if each answer is a string or a list of strings
|
256 |
+
for ans in answers:
|
257 |
+
if isinstance(ans, str):
|
258 |
+
continue
|
259 |
+
elif isinstance(ans, list):
|
260 |
+
if not all(isinstance(a, str) for a in ans):
|
261 |
+
return False
|
262 |
+
else:
|
263 |
+
return False
|
264 |
+
return True
|
265 |
+
except Exception as e:
|
266 |
+
log_print(f"Validation error: {str(e)}", "ERROR")
|
267 |
return False
|
|
|
268 |
|
269 |
if not validate_answers(answers):
|
270 |
log_print("Invalid answer format", "ERROR")
|
271 |
+
log_print(f"Received answer structure: {answers}", "ERROR")
|
272 |
return jsonify({"error": "Invalid answer format"}), 400
|
273 |
|
274 |
+
# Process answers to ensure consistent format
|
275 |
+
processed_answers = []
|
276 |
+
for ans in answers:
|
277 |
+
if isinstance(ans, str):
|
278 |
+
processed_answers.append([ans])
|
279 |
+
else:
|
280 |
+
processed_answers.append(ans)
|
281 |
+
answers = processed_answers
|
282 |
+
|
283 |
# Initialize data structure and parent folder
|
284 |
data = {}
|
285 |
parent_folder = ans_image_dir # Use the temp directory path defined earlier
|