Compare commits

...

10 Commits

3 changed files with 22 additions and 9 deletions
+15 -7
View File
@@ -4349,10 +4349,14 @@ def api_library_scan_action():
due_date = now + datetime.timedelta(days=borrow_duration_days)
it.update_item_status(item_id, False, borrower_name)
app.logger.info(f"Library scan action: borrowing item {item_id} for student card {student_card_id} until {due_date.isoformat()}")
borrower_user = us.get_user_by_student_card(student_card_id)
app.logger.info(f"Found borrower user: {borrower_user}")
if not borrower_user or not borrower_user.get('_id'):
app.logger.warning(f"No user found for student card {student_card_id}. Cannot record borrowing in ausleihungen.")
return jsonify({'ok': False, 'message': 'Kein Benutzer für diesen Schülerausweis gefunden.'}), 404
it.update_item_status(item_id, False, borrower_name)
au.add_ausleihung(
item_id,
str(borrower_user['_id']),
@@ -4367,7 +4371,7 @@ def api_library_scan_action():
'channel': 'library_scan',
'item_id': item_id,
'item_name': item_doc.get('Name', ''),
'borrower':borrower_name,
'borrower': borrower_name,
'student_card_id': student_card_id,
'borrow_duration_days': borrow_duration_days,
}
@@ -4457,6 +4461,7 @@ def api_item_detail(item_id):
db = client[MONGODB_DB]
ausleihungen_col = db['ausleihungen']
items_col = db['items']
student_cards_col = db['student_cards']
# Determine parent/group id (if this is a child, use its ParentItemId)
parent_id = str(item.get('ParentItemId') or str(item.get('_id')))
@@ -4499,8 +4504,9 @@ def api_item_detail(item_id):
if rec.get('Status') == 'active' and rec.get('User'):
try:
user_raw = rec.get('User')
if user_raw is not None:
borrower_value = decrypt_text(str(user_raw))
user_doc = student_cards_col.find_one({'_id': ObjectId(user_raw)}) if user_raw else None
if user_doc:
borrower_value = decrypt_text(str(user_doc.get('SchülerName', ''))) if user_doc.get('SchülerName') else str(user_doc.get('AusweisId', ''))
except Exception:
borrower_value = str(rec.get('User', ''))
break
@@ -4525,11 +4531,13 @@ def api_item_detail(item_id):
rows = []
for rec in borrow_records[:3]:
user_raw = rec.get('User')
try:
user = decrypt_text(user_raw) if user_raw is not None else ''
user_raw = rec.get('User')
user = student_cards_col.find_one({'_id': ObjectId(user_raw)}) if user_raw else None
if user:
borrower_value = decrypt_text(str(user.get('SchülerName', ''))) if user.get('SchülerName') else str(user.get('AusweisId', ''))
except Exception:
user = user_raw
borrower_value = str(rec.get('User', ''))
status = rec.get('Status', '')
start = fmt_dt(rec.get('Start'))
end = fmt_dt(rec.get('End'))
+1 -1
View File
@@ -697,7 +697,7 @@ def get_user_by_student_card(student_card_id):
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
db = _get_tenant_db(client)
users = db['student_cards']
found_user = users.find_one({'SchülerName': normalized})
found_user = users.find_one({'AusweisId': normalized})
client.close()
# Do not call dp.decrypt_text() here because found_user is a MongoDB dictionary.
+6 -1
View File
@@ -266,6 +266,11 @@
border-radius: 4px;
}
.code-search-label {
color: #b93845;
font-weight: 700;
}
.search-button {
padding: 8px 12px;
background-color: #007bff;
@@ -2536,7 +2541,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
<div class="filter-group search-field">
<div class="filter-header">
<label for="code-search">Code suchen:</label>
<label class="code-search-label" for="code-search">Code suchen:</label>
<button type="button" class="clear-filter" onclick="clearCodeSearch()">Clear</button>
</div>
<div class="search-container">