fix of the template name
Release Inventarsystem / release-docker (push) Successful in 2m15s

This commit is contained in:
2026-08-12 11:45:48 +02:00
parent dd3d8649a7
commit 96d45710ac
3 changed files with 83 additions and 61 deletions
+54 -38
View File
@@ -6366,11 +6366,25 @@ def edit_item(id):
return redirect(url_for('home_admin'))
def is_library_item(item):
"""
Prüft, ob ein Artikel ein Bibliotheks-Item ist.
- 'other', None oder Leerstring -> Inventarsystem (False)
- Jeder andere Medientyp ('Buch', 'CD', etc.) -> Bibliothek (True)
"""
if not item:
return False
item_type = item.get('ItemType', 'other')
if not item_type:
return False
return item_type.strip().lower() != 'other'
@app.route('/item_edit/<id>', methods=['GET', 'POST'])
def item_edit(id):
"""
Endpoint zum Bearbeiten von Artikeln (unterstützt Bibliotheks- und Inventar-Modus).
Complete endpoint for editing items. Automatically detects whether the item
is a Library item (ItemType != 'other') or an Inventory item (ItemType == 'other').
"""
if 'username' not in session:
if request.method == 'POST' and request.is_json:
@@ -6391,22 +6405,27 @@ def item_edit(id):
flash('Ungültige Element-ID.', 'error')
return redirect(url_for('home_admin'))
show_library = cfg.MODULES.is_enabled('library')
current_item = it.get_item(obj_id)
if not current_item:
flash('Element in der Datenbank nicht gefunden.', 'error')
return redirect(url_for('home_admin'))
# --- GET: Bearbeitungsformular laden ---
# Determine item type classification
library_module_active = cfg.MODULES.is_enabled('library')
is_lib_item = it.is_library_item(current_item)
show_library_features = library_module_active and is_lib_item
# -------------------------------------------------------------------
# GET METHOD: Render Form
# -------------------------------------------------------------------
if request.method == 'GET':
item = it.get_item(id)
if not item:
flash('Element nicht gefunden.', 'error')
return redirect(url_for('home_admin'))
current_item['_id'] = str(current_item['_id'])
item['_id'] = str(item['_id'])
# Gruppen-Codes aufteilen (Basis-Code vs. Einzelcodes für die Textarea)
base_code = item.get('Code_4', '')
# Format individual group codes for the textarea
base_code = current_item.get('Code_4', '')
individual_codes = []
if item.get('SeriesGroupId'):
group_ids = it.get_group_item_ids(str(item['_id']))
if current_item.get('SeriesGroupId'):
group_ids = it.get_group_item_ids(str(current_item['_id']))
if group_ids:
for gid in group_ids:
g_item = it.get_item(gid)
@@ -6414,26 +6433,23 @@ def item_edit(id):
if c4 and c4 != base_code:
individual_codes.append(c4)
item['IndividualCodes'] = '\n'.join(individual_codes)
current_item['IndividualCodes'] = '\n'.join(individual_codes)
return render_template(
'edit_library.html',
'item_edit.html',
username=session['username'],
item=item,
show_library_features=show_library,
library_module_enabled=show_library,
page_title=f"Bearbeiten: {item.get('Name', '')}"
item=current_item,
show_library_features=show_library_features,
library_module_enabled=library_module_active,
page_title=f"Bearbeiten: {current_item.get('Name', '')}"
)
# --- POST: Änderungen speichern ---
# -------------------------------------------------------------------
# POST METHOD: Save Changes
# -------------------------------------------------------------------
redirect_target = request.referrer or url_for('home_admin')
current_item = it.get_item(obj_id)
if not current_item:
flash('Element in der Datenbank nicht gefunden.', 'error')
return redirect(redirect_target)
# Gemeinsame Felder auslesen & bereinigen
# Common fields
name = sanitize_form_value(request.form.get('name'))
ort = sanitize_form_value(request.form.get('ort'))
beschreibung = sanitize_form_value(request.form.get('beschreibung'))
@@ -6441,7 +6457,7 @@ def item_edit(id):
anschaffungs_kosten = sanitize_form_value(request.form.get('anschaffungskosten'))
reservierbar = 'reservierbar' in request.form
# Barcode & Gruppen-Codes
# Barcodes
code_4 = sanitize_form_value(request.form.get('code_4'))
individual_codes_raw = request.form.get('individual_codes', '')
@@ -6453,7 +6469,7 @@ def item_edit(id):
all_codes_to_check = [code_4] + individual_codes
# Uniqueness-Check für alle übergebenen Barcodes
# Barcode uniqueness check
current_group_id = current_item.get('SeriesGroupId')
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
db_instance = client[cfg.MONGODB_DB]
@@ -6476,9 +6492,9 @@ def item_edit(id):
if has_code_error:
return redirect(redirect_target)
# --- Modi-spezifische Auswertung ---
if show_library:
# 1. Bibliotheks-Modus
# Type-specific processing
if show_library_features:
# --- LIBRARY ITEM ---
isbn_raw = sanitize_form_value(request.form.get('isbn', ''))
item_isbn = normalize_and_validate_isbn(isbn_raw) if isbn_raw else ''
item_type = sanitize_form_value(request.form.get('item_type_input', 'Buch'))
@@ -6489,16 +6505,16 @@ def item_edit(id):
filter3 = current_item.get('Filter3', [])
images = current_item.get('Images', [])
else:
# 2. Inventar-Modus
# --- INVENTORY ITEM ---
item_isbn = current_item.get('ISBN', '')
item_type = current_item.get('ItemType', 'other')
item_type = 'other' # Standard type for inventory items
library_category = current_item.get('library_category', '')
filter1 = expand_filter_selection(sanitize_form_value(request.form.getlist('filter')), 1)
filter2 = expand_filter_selection(sanitize_form_value(request.form.getlist('filter2')), 2)
filter3 = sanitize_form_value(request.form.getlist('filter3'))
# Bilderverarbeitung für den Inventar-Modus
# Manage images for Inventory Mode
images_to_keep = request.form.getlist('existing_images')
original_images = current_item.get('Images', [])
images = [img for img in original_images if img in images_to_keep]
@@ -6537,16 +6553,16 @@ def item_edit(id):
)
images.append(new_filename)
except Exception as e:
app.logger.error(f"Bild-Fehler bei Item {id}: {e}")
app.logger.error(f"Image error for item {id}: {e}")
# Standort bei Bedarf zu vordefinierten Orten hinzufügen
# Auto-add new location to predefined locations list if applicable
if ort and ort not in it.get_predefined_locations():
it.add_predefined_location(ort)
# 1. Gruppen-Codes synchronisieren
# Sync series/group barcode IDs
it.sync_group_codes(str(id), code_4, individual_codes)
# 2. Datenbank-Eintrag aktualisieren
# Update item in database
success = it.update_item(
id=str(id),
name=name,