add detailed error messages
This commit is contained in:
parent
b4f7c8eae0
commit
b3d4f4a198
27
app.py
27
app.py
@ -82,12 +82,29 @@ def upload():
|
|||||||
return render_template('upload.html', error='Ungültige Excel-Datei')
|
return render_template('upload.html', error='Ungültige Excel-Datei')
|
||||||
# mandatory columns
|
# mandatory columns
|
||||||
required = ['question','answer1','answer2','answer3','answer4','correct']
|
required = ['question','answer1','answer2','answer3','answer4','correct']
|
||||||
if not all(col in df.columns for col in required):
|
# ermittelt, welche der benötigten Spalten nicht im DataFrame sind
|
||||||
return render_template('upload.html', error=f'Fehler in Datei: Fehlende Spalten. Erforderlich: {required}')
|
missing = [col for col in required if col not in df.columns]
|
||||||
|
if missing:
|
||||||
|
return render_template(
|
||||||
|
'upload.html',
|
||||||
|
error=f"Fehler in Datei: Fehlende Spalte(n): {', '.join(missing)}"
|
||||||
|
)
|
||||||
# validate that 'correct' references one of the answer columns
|
# validate that 'correct' references one of the answer columns
|
||||||
if not df['correct'].isin(['answer1','answer2','answer3','answer4']).all():
|
valid_keys = ['answer1','answer2','answer3','answer4']
|
||||||
return render_template('upload.html', error='Fehler in Datei: Antwortspalte "correct" muss einen der Werte "answer1", "answer2", "answer3" oder "answer4" enthalten.')
|
invalid_mask = ~df['correct'].isin(valid_keys)
|
||||||
# build per-game question list
|
if invalid_mask.any():
|
||||||
|
# finde den ersten Invalid-Eintrag
|
||||||
|
idx = invalid_mask.idxmax() # DataFrame-Index
|
||||||
|
excel_line = idx + 2 # Header ist Zeile 1
|
||||||
|
bad_value = df.at[idx, 'correct']
|
||||||
|
return render_template(
|
||||||
|
'upload.html',
|
||||||
|
error=(
|
||||||
|
f'Fehler in Zeile {excel_line}: '
|
||||||
|
f'"correct" enthält "{bad_value}", '
|
||||||
|
f'muss einer der Werte {valid_keys} sein.'
|
||||||
|
)
|
||||||
|
) # build per-game question list
|
||||||
questions = []
|
questions = []
|
||||||
for _, row in df.iterrows():
|
for _, row in df.iterrows():
|
||||||
col = row['correct']
|
col = row['correct']
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user