This commit is contained in:
@@ -29,23 +29,20 @@ import Web.modules.inventarsystem.data_protection as dp
|
||||
|
||||
def is_library_item(item):
|
||||
"""
|
||||
Determines if an item belongs to the library system.
|
||||
Prioritizes explicit 'is_library' boolean field from MongoDB if set.
|
||||
Ermittelt zuverlässig, ob ein Objekt zur Bibliothek gehört.
|
||||
Gibt True zurück, wenn ItemType ein Medientyp ist (Buch, Schulbuch, CD, DVD etc.)
|
||||
ODER wenn is_library explizit True ist.
|
||||
"""
|
||||
if not item:
|
||||
return False
|
||||
|
||||
# 1. Check explicit boolean flag from MongoDB first
|
||||
if 'is_library' in item and item['is_library'] is not None:
|
||||
return bool(item['is_library'])
|
||||
# 1. Prüfe zuerst den Medientyp (ItemType)
|
||||
item_type = str(item.get('ItemType', '') or '').strip().lower()
|
||||
if item_type and item_type not in ['other', 'general', 'none', 'null']:
|
||||
return True
|
||||
|
||||
# 2. Fallback to ItemType check
|
||||
item_type = item.get('ItemType', 'other')
|
||||
if not item_type:
|
||||
return False
|
||||
|
||||
clean_type = str(item_type).strip().lower()
|
||||
return clean_type not in ['other', 'general', '']
|
||||
# 2. Falls ItemType 'other' ist, prüfe das is_library Flag
|
||||
return bool(item.get('is_library', False))
|
||||
|
||||
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,
|
||||
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:
|
||||
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')
|
||||
|
||||
# Recalculate library status based on updated item_type
|
||||
is_lib = is_library_item({'is_library': old_item.get('is_library'), 'ItemType': item_type})
|
||||
# is_library automatisch anhand des neuen item_type bestimmen
|
||||
is_lib = is_library_item({'ItemType': item_type})
|
||||
|
||||
shared_update = {
|
||||
'Name': name,
|
||||
|
||||
Reference in New Issue
Block a user