Compare commits

...

2 Commits

Author SHA1 Message Date
Aiirondev_dev d58958db39 Changes to habe he template name right and the right correction for the library Item and a parameter mismatch
Release Inventarsystem / release-docker (push) Successful in 2m22s
2026-08-12 12:26:10 +02:00
Aiirondev_dev 9452743660 Changes to reflekt the right inventar and bibliothek item fields
Release Inventarsystem / release-docker (push) Successful in 2m17s
2026-08-12 11:59:57 +02:00
3 changed files with 69 additions and 66 deletions
+17 -20
View File
@@ -6383,8 +6383,8 @@ def is_library_item(item):
@app.route('/item_edit/<id>', methods=['GET', 'POST'])
def item_edit(id):
"""
Complete endpoint for editing items. Automatically detects whether the item
is a Library item (ItemType != 'other') or an Inventory item (ItemType == 'other').
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 request.method == 'POST' and request.is_json:
@@ -6410,7 +6410,7 @@ def item_edit(id):
flash('Element in der Datenbank nicht gefunden.', 'error')
return redirect(url_for('home_admin'))
# Determine item type classification
# Determine item 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
@@ -6435,8 +6435,9 @@ def item_edit(id):
current_item['IndividualCodes'] = '\n'.join(individual_codes)
# FIXED: Changed 'edit_library.html' to 'item_edit.html'
return render_template(
'edit_library.html',
'item_edit.html',
username=session['username'],
item=current_item,
show_library_features=show_library_features,
@@ -6457,7 +6458,12 @@ def item_edit(id):
anschaffungs_kosten = sanitize_form_value(request.form.get('anschaffungskosten'))
reservierbar = 'reservierbar' in request.form
# Barcodes
# System Filters 1, 2, and 3 (Processed for ALL items)
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'))
# Barcodes & Group Codes
code_4 = sanitize_form_value(request.form.get('code_4'))
individual_codes_raw = request.form.get('individual_codes', '')
@@ -6494,27 +6500,17 @@ def item_edit(id):
# 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'))
library_category = sanitize_form_value(request.form.get('library_category', ''))
filter1 = current_item.get('Filter', [])
filter2 = current_item.get('Filter2', [])
filter3 = current_item.get('Filter3', [])
images = current_item.get('Images', [])
else:
# --- INVENTORY ITEM ---
item_isbn = current_item.get('ISBN', '')
item_type = 'other' # Standard type for inventory items
item_type = 'other'
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'))
# Manage images for Inventory Mode
# Manage images for Inventory Items
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]
@@ -6555,14 +6551,14 @@ def item_edit(id):
except Exception as e:
app.logger.error(f"Image error for item {id}: {e}")
# Auto-add new location to predefined locations list if applicable
# Auto-add location if applicable
if ort and ort not in it.get_predefined_locations():
it.add_predefined_location(ort)
# Sync series/group barcode IDs
# Sync group barcodes
it.sync_group_codes(str(id), code_4, individual_codes)
# Update item in database
# Save to MongoDB
success = it.update_item(
id=str(id),
name=name,
@@ -6588,6 +6584,7 @@ def item_edit(id):
flash('Fehler beim Aktualisieren des Artikels.', 'error')
return redirect(redirect_target)
@app.route('/update_group', methods=['POST'])
def update_group():
+28 -12
View File
@@ -30,15 +30,22 @@ import Web.modules.inventarsystem.data_protection as dp
def is_library_item(item):
"""
Determines if an item belongs to the library system.
Returns False for 'other', None, or empty ItemType (Inventory item).
Returns True for any specific library type ('Buch', 'CD', 'DVD', etc.).
Prioritizes explicit 'is_library' boolean field from MongoDB if set.
"""
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'])
# 2. Fallback to ItemType check
item_type = item.get('ItemType', 'other')
if not item_type:
return False
return str(item_type).strip().lower() != 'other'
clean_type = str(item_type).strip().lower()
return clean_type not in ['other', 'general', '']
def safe_decrypt_user(encrypted_user):
"""
@@ -264,7 +271,10 @@ 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=None, item_type='general'):
ansch_jahr, ansch_kost, code_4, reservierbar, isbn="", item_type='other', library_category=""):
"""
Updates an item in MongoDB, keeping series groups synchronized.
"""
try:
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
db = client[cfg.MONGODB_DB]
@@ -272,29 +282,35 @@ def update_item(id, name, ort, beschreibung, images, verfuegbar, filter1, filter
old_item = items.find_one({'_id': ObjectId(id)})
if not old_item:
client.close()
return False
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})
shared_update = {
'Name': name,
'Ort': ort,
'Beschreibung': beschreibung,
'Images': images,
'Filter': filter1,
'Filter2': filter2,
'Filter3': filter3,
'Images': images if isinstance(images, list) else [],
'Filter': filter1 if isinstance(filter1, list) else [],
'Filter2': filter2 if isinstance(filter2, list) else [],
'Filter3': filter3 if isinstance(filter3, list) else [],
'Anschaffungsjahr': ansch_jahr,
'Anschaffungskosten': ansch_kost,
'Reservierbar': reservierbar,
'ISBN': isbn,
'Reservierbar': bool(reservierbar),
'ISBN': str(isbn) if isbn else '',
'ItemType': item_type,
'Verfuegbar': verfuegbar,
'is_library': is_lib,
'library_category': library_category,
'Verfuegbar': bool(verfuegbar),
'LastUpdated': datetime.datetime.now()
}
specific_update = shared_update.copy()
specific_update['Code_4'] = code_4
specific_update['Code_4'] = str(code_4) if code_4 else ''
items.update_one({'_id': ObjectId(id)}, {'$set': specific_update})
+24 -34
View File
@@ -103,7 +103,7 @@
background-color: #0056b3;
}
/* Scanner Video Canvas */
/* Scanner Elements */
#code4-scanner video, #code4-scanner canvas,
#isbn-scanner video, #isbn-scanner canvas {
width: 100%;
@@ -197,7 +197,7 @@
<input type="hidden" name="item_id" value="{{ item._id }}">
{% if show_library_features %}
<!-- ================= LIBRARY MODE FIELDS ================= -->
<!-- ================= LIBRARY SPECIFIC FIELDS ================= -->
<div class="form-group">
<label for="isbn">ISBN / Barcode:</label>
<div class="isbn-input-group">
@@ -209,9 +209,26 @@
<small id="isbn-scan-status" style="display:block; color:#666; margin-top:6px;"></small>
<div id="book-info-container"></div>
</div>
<div class="filter-inputs" style="margin-bottom: 20px;">
<h3>Medientyp</h3>
<div class="form-group">
<select name="item_type_input" id="item_type_input">
<option value="Buch" {% if item.ItemType == 'Buch' %}selected{% endif %}>Buch</option>
<option value="Schulbuch" {% if item.ItemType == 'Schulbuch' %}selected{% endif %}>Schulbuch</option>
<option value="CD" {% if item.ItemType == 'CD' %}selected{% endif %}>CD</option>
<option value="DVD" {% if item.ItemType == 'DVD' %}selected{% endif %}>DVD</option>
<option value="Sonstiges" {% if item.ItemType == 'Sonstiges' %}selected{% endif %}>Sonstiges</option>
</select>
</div>
<h3>Bibliotheks-Kategorie:</h3>
<div class="form-group">
<input type="text" name="library_category" id="library_category" value="{{ item.library_category|default('') }}" placeholder="z.B. Belletristik, Sachbücher, etc.">
</div>
</div>
{% endif %}
<!-- ================= COMMON FIELDS ================= -->
<!-- ================= COMMON CORE FIELDS ================= -->
<div class="form-group">
<label for="name">Name / Titel:</label>
<input type="text" id="name" name="name" value="{{ item.Name|default('') }}" required>
@@ -254,26 +271,7 @@
<small style="display:block; color:#666; margin-top: 5px;">Der Basis-Code steht oben. Alle weiteren Gruppenmitglieder werden hier untereinander aufgeführt.</small>
</div>
{% if show_library_features %}
<!-- ================= LIBRARY CATEGORIZATION ================= -->
<div class="filter-inputs">
<h3>Medientyp</h3>
<div class="form-group">
<select name="item_type_input" id="item_type_input">
<option value="Buch" {% if item.ItemType == 'Buch' %}selected{% endif %}>Buch</option>
<option value="Schulbuch" {% if item.ItemType == 'Schulbuch' %}selected{% endif %}>Schulbuch</option>
<option value="CD" {% if item.ItemType == 'CD' %}selected{% endif %}>CD</option>
<option value="DVD" {% if item.ItemType == 'DVD' %}selected{% endif %}>DVD</option>
<option value="Sonstiges" {% if item.ItemType == 'Sonstiges' %}selected{% endif %}>Sonstiges</option>
</select>
</div>
<h3>Kategorie / Fach:</h3>
<div class="form-group">
<input type="text" name="library_category" id="library_category" value="{{ item.library_category|default('') }}" placeholder="z.B. Belletristik, Sachbücher, etc.">
</div>
</div>
{% else %}
<!-- ================= INVENTORY FILTERS (1-3) ================= -->
<!-- ================= SYSTEM FILTERS 1-3 (ALWAYS RENDERED) ================= -->
<div class="filter-inputs">
<h3>Unterrichtsfach (Filter 1):</h3>
<div class="multi-filter">
@@ -309,7 +307,6 @@
{% endfor %}
</div>
</div>
{% endif %}
<!-- ================= DATES & FINANCIALS ================= -->
<div class="form-group">
@@ -358,13 +355,11 @@
<script src="https://cdn.jsdelivr.net/npm/@ericblade/quagga2/dist/quagga.js"></script>
<script>
const libraryModuleEnabled = {{ 'true' if show_library_features else 'false' }};
let scannerRunning = false;
let activeScannerCallback = null;
let code4LastScanned = '';
let code4LastScannedAt = 0;
// Load filter dropdown options and pre-select current item values
function loadAndSelectFilterValues(filterNumber) {
fetch(`/get_predefined_filter_values/${filterNumber}`)
.then(res => res.json())
@@ -383,7 +378,6 @@
select.appendChild(opt);
});
// Add custom option if the item has a value not in predefined list
if (selectedValue && !Array.from(select.options).some(o => o.value === selectedValue)) {
const customOpt = document.createElement('option');
customOpt.value = selectedValue;
@@ -397,7 +391,6 @@
.catch(err => console.error(`Error loading Filter ${filterNumber}:`, err));
}
// Load locations
function loadLocationOptions() {
fetch('/get_predefined_locations')
.then(res => res.json())
@@ -420,7 +413,6 @@
.catch(err => console.error('Error loading locations:', err));
}
// New location handler
function addNewLocation() {
const input = document.getElementById('new-location-input');
const val = input.value.trim();
@@ -440,7 +432,6 @@
document.getElementById('new-location-input').value = '';
}
// Quagga Barcode Scanner Engine
function runEngineInitialization(targetSelector, activeCallback, completionMsg, errorStatusSetter) {
if (scannerRunning) { Quagga.stop(); scannerRunning = false; }
activeScannerCallback = activeCallback;
@@ -497,10 +488,9 @@
document.addEventListener('DOMContentLoaded', function() {
loadLocationOptions();
if (!libraryModuleEnabled) {
loadAndSelectFilterValues(1);
loadAndSelectFilterValues(2);
}
// Always load Filter 1 and Filter 2 options for all items
loadAndSelectFilterValues(1);
loadAndSelectFilterValues(2);
const scanCodeBtn = document.getElementById('scan-code4-btn');
if (scanCodeBtn) scanCodeBtn.addEventListener('click', startCode4Scanner);