fix of the json upload format
This commit is contained in:
+25
-20
@@ -11850,37 +11850,40 @@ def test_push_notification():
|
||||
return jsonify({'success': False}), 500
|
||||
|
||||
|
||||
@app.route('/batch_upload', methods=['GET'])
|
||||
def batch_upload_page():
|
||||
"""
|
||||
Serves the HTML frontend for the batch CSV and image upload.
|
||||
"""
|
||||
# Check permissions if necessary, similar to your other routes
|
||||
if 'username' not in session:
|
||||
flash('Bitte melden Sie sich an.', 'error')
|
||||
return redirect(url_for('login'))
|
||||
|
||||
return render_template('upload_batch.html')
|
||||
|
||||
|
||||
def clean_db_field(val):
|
||||
"""Bereinigt Werte, die fälschlicherweise als String-Listen aus der CSV kommen."""
|
||||
"""Bereinigt Werte, die fälschlicherweise als String-Listen oder mit Klammern aus der CSV kommen."""
|
||||
import ast
|
||||
import pandas as pd
|
||||
|
||||
if not val or pd.isna(val):
|
||||
return None
|
||||
|
||||
val_str = str(val).strip()
|
||||
|
||||
# Erkennt und entpackt String-Listen wie "['100465']" oder '["100465"]'
|
||||
if (val_str.startswith("['") and val_str.endswith("']")) or (val_str.startswith('["') and val_str.endswith('"]')):
|
||||
inner = val_str[2:-2].strip()
|
||||
return inner if inner and inner != "''" and inner != '""' else None
|
||||
# Wenn es wie eine Liste aussieht (z.B. "['100177']" oder "['']")
|
||||
if val_str.startswith("[") and val_str.endswith("]"):
|
||||
try:
|
||||
parsed = ast.literal_eval(val_str)
|
||||
if isinstance(parsed, list):
|
||||
# Nimm das erste Element der Liste, wenn vorhanden
|
||||
for item in parsed:
|
||||
cleaned_item = str(item).strip()
|
||||
if cleaned_item and cleaned_item not in ("", "''", '""', "None", "nan"):
|
||||
return cleaned_item
|
||||
return None
|
||||
except Exception:
|
||||
# Fallback bei Syntaxfehlern
|
||||
inner = val_str[1:-1].strip().replace("'", "").replace('"', '')
|
||||
return inner if inner and inner not in ("''", '""') else None
|
||||
|
||||
if val_str in ("[]", "['']", '[""]', "nan", "None"):
|
||||
if val_str in ("[]", "['']", '[""]', "nan", "None", "''", '""'):
|
||||
return None
|
||||
|
||||
return val_str
|
||||
|
||||
|
||||
|
||||
@app.route('/upload_csv_batch', methods=['POST'])
|
||||
def upload_csv_batch():
|
||||
"""
|
||||
@@ -12064,8 +12067,10 @@ def upload_csv_batch():
|
||||
|
||||
reservierbar = bool(row.get('Reservierbar', False))
|
||||
|
||||
# Code_4 Behandlung
|
||||
row_code = clean_db_field(row.get('Code_4', ''))
|
||||
# Code_4 / Barcode sauber extrahieren und bereinigen
|
||||
raw_code = row.get('Code_4') or row.get('Barcode') or ''
|
||||
row_code = clean_db_field(raw_code)
|
||||
|
||||
if row_code:
|
||||
unique_code = row_code
|
||||
elif item_count > 1:
|
||||
|
||||
Reference in New Issue
Block a user