This commit is contained in:
+6
-20
@@ -6382,10 +6382,6 @@ def is_library_item(item):
|
|||||||
|
|
||||||
@app.route('/item_edit/<id>', methods=['GET', 'POST'])
|
@app.route('/item_edit/<id>', methods=['GET', 'POST'])
|
||||||
def item_edit(id):
|
def item_edit(id):
|
||||||
"""
|
|
||||||
Endpoint for editing items. Correctly determines library vs inventory status
|
|
||||||
and renders Filter 1-3 for ALL item types.
|
|
||||||
"""
|
|
||||||
if 'username' not in session:
|
if 'username' not in session:
|
||||||
if request.method == 'POST' and request.is_json:
|
if request.method == 'POST' and request.is_json:
|
||||||
return jsonify({'success': False, 'message': 'Nicht angemeldet.'}), 401
|
return jsonify({'success': False, 'message': 'Nicht angemeldet.'}), 401
|
||||||
@@ -6410,18 +6406,17 @@ def item_edit(id):
|
|||||||
flash('Element in der Datenbank nicht gefunden.', 'error')
|
flash('Element in der Datenbank nicht gefunden.', 'error')
|
||||||
return redirect(url_for('home_admin'))
|
return redirect(url_for('home_admin'))
|
||||||
|
|
||||||
# Determine item classification
|
# Bibliothek-Status ermitteln
|
||||||
library_module_active = cfg.MODULES.is_enabled('library')
|
library_module_active = cfg.MODULES.is_enabled('library')
|
||||||
is_lib_item = it.is_library_item(current_item)
|
is_lib_item = it.is_library_item(current_item)
|
||||||
show_library_features = library_module_active and is_lib_item
|
show_library_features = library_module_active and is_lib_item
|
||||||
|
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
# GET METHOD: Render Form
|
# GET METHOD
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
current_item['_id'] = str(current_item['_id'])
|
current_item['_id'] = str(current_item['_id'])
|
||||||
|
|
||||||
# Format individual group codes for the textarea
|
|
||||||
base_code = current_item.get('Code_4', '')
|
base_code = current_item.get('Code_4', '')
|
||||||
individual_codes = []
|
individual_codes = []
|
||||||
if current_item.get('SeriesGroupId'):
|
if current_item.get('SeriesGroupId'):
|
||||||
@@ -6435,7 +6430,6 @@ def item_edit(id):
|
|||||||
|
|
||||||
current_item['IndividualCodes'] = '\n'.join(individual_codes)
|
current_item['IndividualCodes'] = '\n'.join(individual_codes)
|
||||||
|
|
||||||
# FIXED: Changed 'edit_library.html' to 'item_edit.html'
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'edit_library.html',
|
'edit_library.html',
|
||||||
username=session['username'],
|
username=session['username'],
|
||||||
@@ -6446,11 +6440,10 @@ def item_edit(id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
# POST METHOD: Save Changes
|
# POST METHOD
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
redirect_target = request.referrer or url_for('home_admin')
|
redirect_target = request.referrer or url_for('home_admin')
|
||||||
|
|
||||||
# Common fields
|
|
||||||
name = sanitize_form_value(request.form.get('name'))
|
name = sanitize_form_value(request.form.get('name'))
|
||||||
ort = sanitize_form_value(request.form.get('ort'))
|
ort = sanitize_form_value(request.form.get('ort'))
|
||||||
beschreibung = sanitize_form_value(request.form.get('beschreibung'))
|
beschreibung = sanitize_form_value(request.form.get('beschreibung'))
|
||||||
@@ -6458,12 +6451,11 @@ def item_edit(id):
|
|||||||
anschaffungs_kosten = sanitize_form_value(request.form.get('anschaffungskosten'))
|
anschaffungs_kosten = sanitize_form_value(request.form.get('anschaffungskosten'))
|
||||||
reservierbar = 'reservierbar' in request.form
|
reservierbar = 'reservierbar' in request.form
|
||||||
|
|
||||||
# System Filters 1, 2, and 3 (Processed for ALL items)
|
# Filter 1-3 für alle Objekte
|
||||||
filter1 = expand_filter_selection(sanitize_form_value(request.form.getlist('filter')), 1)
|
filter1 = expand_filter_selection(sanitize_form_value(request.form.getlist('filter')), 1)
|
||||||
filter2 = expand_filter_selection(sanitize_form_value(request.form.getlist('filter2')), 2)
|
filter2 = expand_filter_selection(sanitize_form_value(request.form.getlist('filter2')), 2)
|
||||||
filter3 = sanitize_form_value(request.form.getlist('filter3'))
|
filter3 = sanitize_form_value(request.form.getlist('filter3'))
|
||||||
|
|
||||||
# Barcodes & Group Codes
|
|
||||||
code_4 = sanitize_form_value(request.form.get('code_4'))
|
code_4 = sanitize_form_value(request.form.get('code_4'))
|
||||||
individual_codes_raw = request.form.get('individual_codes', '')
|
individual_codes_raw = request.form.get('individual_codes', '')
|
||||||
|
|
||||||
@@ -6475,7 +6467,6 @@ def item_edit(id):
|
|||||||
|
|
||||||
all_codes_to_check = [code_4] + individual_codes
|
all_codes_to_check = [code_4] + individual_codes
|
||||||
|
|
||||||
# Barcode uniqueness check
|
|
||||||
current_group_id = current_item.get('SeriesGroupId')
|
current_group_id = current_item.get('SeriesGroupId')
|
||||||
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
|
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
|
||||||
db_instance = client[cfg.MONGODB_DB]
|
db_instance = client[cfg.MONGODB_DB]
|
||||||
@@ -6498,19 +6489,17 @@ def item_edit(id):
|
|||||||
if has_code_error:
|
if has_code_error:
|
||||||
return redirect(redirect_target)
|
return redirect(redirect_target)
|
||||||
|
|
||||||
# Type-specific processing
|
|
||||||
if show_library_features:
|
if show_library_features:
|
||||||
isbn_raw = sanitize_form_value(request.form.get('isbn', ''))
|
isbn_raw = sanitize_form_value(request.form.get('isbn', ''))
|
||||||
item_isbn = normalize_and_validate_isbn(isbn_raw) if isbn_raw else ''
|
item_isbn = normalize_and_validate_isbn(isbn_raw) if isbn_raw else ''
|
||||||
item_type = sanitize_form_value(request.form.get('item_type_input', 'Buch'))
|
item_type = sanitize_form_value(request.form.get('item_type_input', current_item.get('ItemType', 'Buch')))
|
||||||
library_category = sanitize_form_value(request.form.get('library_category', ''))
|
library_category = sanitize_form_value(request.form.get('library_category', ''))
|
||||||
images = current_item.get('Images', [])
|
images = current_item.get('Images', [])
|
||||||
else:
|
else:
|
||||||
item_isbn = current_item.get('ISBN', '')
|
item_isbn = current_item.get('ISBN', '')
|
||||||
item_type = 'other'
|
item_type = current_item.get('ItemType', 'other')
|
||||||
library_category = current_item.get('library_category', '')
|
library_category = current_item.get('library_category', '')
|
||||||
|
|
||||||
# Manage images for Inventory Items
|
|
||||||
images_to_keep = request.form.getlist('existing_images')
|
images_to_keep = request.form.getlist('existing_images')
|
||||||
original_images = current_item.get('Images', [])
|
original_images = current_item.get('Images', [])
|
||||||
images = [img for img in original_images if img in images_to_keep]
|
images = [img for img in original_images if img in images_to_keep]
|
||||||
@@ -6551,14 +6540,11 @@ def item_edit(id):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
app.logger.error(f"Image error for item {id}: {e}")
|
app.logger.error(f"Image error for item {id}: {e}")
|
||||||
|
|
||||||
# Auto-add location if applicable
|
|
||||||
if ort and ort not in it.get_predefined_locations():
|
if ort and ort not in it.get_predefined_locations():
|
||||||
it.add_predefined_location(ort)
|
it.add_predefined_location(ort)
|
||||||
|
|
||||||
# Sync group barcodes
|
|
||||||
it.sync_group_codes(str(id), code_4, individual_codes)
|
it.sync_group_codes(str(id), code_4, individual_codes)
|
||||||
|
|
||||||
# Save to MongoDB
|
|
||||||
success = it.update_item(
|
success = it.update_item(
|
||||||
id=str(id),
|
id=str(id),
|
||||||
name=name,
|
name=name,
|
||||||
|
|||||||
@@ -29,23 +29,20 @@ import Web.modules.inventarsystem.data_protection as dp
|
|||||||
|
|
||||||
def is_library_item(item):
|
def is_library_item(item):
|
||||||
"""
|
"""
|
||||||
Determines if an item belongs to the library system.
|
Ermittelt zuverlässig, ob ein Objekt zur Bibliothek gehört.
|
||||||
Prioritizes explicit 'is_library' boolean field from MongoDB if set.
|
Gibt True zurück, wenn ItemType ein Medientyp ist (Buch, Schulbuch, CD, DVD etc.)
|
||||||
|
ODER wenn is_library explizit True ist.
|
||||||
"""
|
"""
|
||||||
if not item:
|
if not item:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 1. Check explicit boolean flag from MongoDB first
|
# 1. Prüfe zuerst den Medientyp (ItemType)
|
||||||
if 'is_library' in item and item['is_library'] is not None:
|
item_type = str(item.get('ItemType', '') or '').strip().lower()
|
||||||
return bool(item['is_library'])
|
if item_type and item_type not in ['other', 'general', 'none', 'null']:
|
||||||
|
return True
|
||||||
|
|
||||||
# 2. Fallback to ItemType check
|
# 2. Falls ItemType 'other' ist, prüfe das is_library Flag
|
||||||
item_type = item.get('ItemType', 'other')
|
return bool(item.get('is_library', False))
|
||||||
if not item_type:
|
|
||||||
return False
|
|
||||||
|
|
||||||
clean_type = str(item_type).strip().lower()
|
|
||||||
return clean_type not in ['other', 'general', '']
|
|
||||||
|
|
||||||
def safe_decrypt_user(encrypted_user):
|
def safe_decrypt_user(encrypted_user):
|
||||||
"""
|
"""
|
||||||
@@ -273,7 +270,7 @@ def get_group_item_ids(id):
|
|||||||
def update_item(id, name, ort, beschreibung, images, verfuegbar, filter1, filter2, filter3,
|
def update_item(id, name, ort, beschreibung, images, verfuegbar, filter1, filter2, filter3,
|
||||||
ansch_jahr, ansch_kost, code_4, reservierbar, isbn="", item_type='other', library_category=""):
|
ansch_jahr, ansch_kost, code_4, reservierbar, isbn="", item_type='other', library_category=""):
|
||||||
"""
|
"""
|
||||||
Updates an item in MongoDB, keeping series groups synchronized.
|
Aktualisiert ein Objekt in MongoDB und setzt is_library korrekt basierend auf dem Medientyp.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
|
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
|
||||||
@@ -287,8 +284,8 @@ def update_item(id, name, ort, beschreibung, images, verfuegbar, filter1, filter
|
|||||||
|
|
||||||
series_group_id = old_item.get('SeriesGroupId')
|
series_group_id = old_item.get('SeriesGroupId')
|
||||||
|
|
||||||
# Recalculate library status based on updated item_type
|
# is_library automatisch anhand des neuen item_type bestimmen
|
||||||
is_lib = is_library_item({'is_library': old_item.get('is_library'), 'ItemType': item_type})
|
is_lib = is_library_item({'ItemType': item_type})
|
||||||
|
|
||||||
shared_update = {
|
shared_update = {
|
||||||
'Name': name,
|
'Name': name,
|
||||||
|
|||||||
Reference in New Issue
Block a user