From 2892024969cd58fcb56f7aab85a8116296f1c7c6 Mon Sep 17 00:00:00 2001 From: AIIrondev Date: Mon, 3 Aug 2026 23:26:51 +0200 Subject: [PATCH] fix of the json upload format --- Web/app.py | 25 ++- Web/templates/upload_batch.html | 266 +++++++++++++++++++++----------- 2 files changed, 203 insertions(+), 88 deletions(-) diff --git a/Web/app.py b/Web/app.py index 7b39370..7da0445 100755 --- a/Web/app.py +++ b/Web/app.py @@ -11883,6 +11883,20 @@ def upload_csv_batch(): username = session.get('username', 'System') + def generate_unique_batch_code(base_code, position): + """ + Generiert einen eindeutigen Code für einen Artikel innerhalb einer Serie (Batch). + + :param base_code: Der Code des ersten Artikels in der Gruppe (String oder None). + :param position: Die Position des aktuellen Artikels in der Gruppe (Integer). + :return: Ein eindeutiger Code als String. + """ + if base_code: + return f"{base_code}-{position}" + else: + random_prefix = str(uuid.uuid4())[:6].upper() + return f"BATCH-{random_prefix}-{position}" + fs = get_gridfs() upload_session_id = str(uuid.uuid4())[:8] app.logger.info(f"Starting CSV Batch upload session {upload_session_id} - User: {username}") @@ -12029,6 +12043,15 @@ def upload_csv_batch(): except (ValueError, SyntaxError): pass + # --- NEU: BILDER-REFERENZEN PRO ARTIKEL DEDUPLIZIEREN --- + # Falls die CSV z.B. ['bild1.jpg', 'bild1.jpg'] enthält, filtern wir das hier heraus, + # damit die GridFS-Datei nicht doppelt als Referenz gespeichert wird. + unique_image_filenames = [] + for img in item_image_filenames: + if img not in unique_image_filenames: + unique_image_filenames.append(img) + # -------------------------------------------------------- + def parse_filter_col(col_data): try: res = ast.literal_eval(str(col_data)) @@ -12056,7 +12079,7 @@ def upload_csv_batch(): str(row['Name']), # 1. Name ort_val, # 2. Ort str(row['Beschreibung']), # 3. Beschreibung - item_image_filenames, # 4. Image Filenames (GridFS) + unique_image_filenames, # 4. Image Filenames (GridFS) -> HIER GEÄNDERT filter_upload, # 5. Filter 1 filter_upload2, # 6. Filter 2 filter_upload3, # 7. Filter 3 diff --git a/Web/templates/upload_batch.html b/Web/templates/upload_batch.html index d5108fc..b998285 100644 --- a/Web/templates/upload_batch.html +++ b/Web/templates/upload_batch.html @@ -21,6 +21,8 @@ align-items: center; min-height: 100vh; margin: 0; + padding: 20px; + box-sizing: border-box; } .upload-container { @@ -56,6 +58,7 @@ border-radius: var(--border-radius); background: #fafafa; cursor: pointer; + box-sizing: border-box; } .btn-submit { @@ -80,47 +83,48 @@ cursor: not-allowed; } - /* Status & Feedback Messages */ - #status-message { - margin-top: 1rem; - padding: 1rem; - border-radius: var(--border-radius); + /* Fortschritts- und Log-Bereich */ + #uploadProgress { + margin-top: 2rem; display: none; + } + + #progressText { + font-size: 1rem; + margin-bottom: 0.5rem; + color: var(--primary-color); text-align: center; } - .success { - background-color: #d4edda; - color: #155724; - border: 1px solid #c3e6cb; + progress { + width: 100%; + height: 20px; + border-radius: var(--border-radius); } - .error { - background-color: #f8d7da; - color: #721c24; - border: 1px solid #f5c6cb; + #logList { + margin-top: 1rem; + padding: 10px; + font-size: 0.85rem; + color: #555; + max-height: 150px; + overflow-y: auto; + background: #fafafa; + border: 1px solid #ddd; + border-radius: var(--border-radius); + list-style-type: none; } - .loading { - background-color: #e2e3e5; - color: #383d41; - border: 1px solid #d6d8db; + #logList li { + margin-bottom: 5px; + padding-bottom: 5px; + border-bottom: 1px solid #eee; } - .spinner { - display: inline-block; - width: 1.5rem; - height: 1.5rem; - border: 3px solid rgba(0,0,0,0.1); - border-radius: 50%; - border-top-color: var(--primary-color); - animation: spin 1s ease-in-out infinite; - vertical-align: middle; - margin-right: 0.5rem; - } - - @keyframes spin { - to { transform: rotate(360deg); } + #logList li:last-child { + border-bottom: none; + margin-bottom: 0; + padding-bottom: 0; } @@ -129,89 +133,177 @@

Inventar Batch Upload

-
+ +
-
- Du kannst mehrere Bilder markieren (Strg/Cmd gedrückt halten).
- + +
-
+ +
+
Starte Upload...
+ +
    +
    \ No newline at end of file + + progressBar.value = b + 1; + } + + progressText.textContent = "Upload-Vorgang abgeschlossen!"; + uploadBtn.disabled = false; + + } catch (error) { + alert("Fehler bei der Verarbeitung des Uploads: " + error.message); + log("Fehler: " + error.message); + uploadBtn.disabled = false; + } +}); + + + \ No newline at end of file