Change of the notification-reminder
Release Inventarsystem / release-docker (push) Successful in 2m15s
Release Inventarsystem / release-docker (push) Successful in 2m15s
This commit is contained in:
+29
-21
@@ -1160,8 +1160,8 @@ def _build_reminder_message(item_name, start_dt=None, end_dt=None):
|
||||
)
|
||||
|
||||
|
||||
def create_return_reminders():
|
||||
"""Create one-time reminders for day-1 and planned-end events."""
|
||||
def create_return_reminders_admin():
|
||||
"""Create one-time reminders for day-1 and planned-end events for admins."""
|
||||
now = datetime.datetime.now(ZoneInfo("Europe/Berlin"))
|
||||
one_day_ago = now - datetime.timedelta(days=1)
|
||||
|
||||
@@ -1202,9 +1202,14 @@ def create_return_reminders():
|
||||
for borrow_doc in candidates:
|
||||
borrow_id = str(borrow_doc.get('_id'))
|
||||
username = str(borrow_doc.get('User', '')).strip()
|
||||
|
||||
if not borrow_id or not username:
|
||||
continue
|
||||
|
||||
# Falls der Benutzername verschlüsselt ist, hier entschlüsseln,
|
||||
# damit der Admin den echten Namen/Ausweis lesen kann.
|
||||
display_user = decrypt_text(username) if 'decrypt_text' in globals() else username
|
||||
|
||||
item_id = str(borrow_doc.get('Item', '')).strip()
|
||||
item_doc = item_docs.get(item_id, {})
|
||||
item_name = item_doc.get('Name') or f'Item {item_id}'
|
||||
@@ -1215,30 +1220,33 @@ def create_return_reminders():
|
||||
if isinstance(start_dt, datetime.datetime) and start_dt <= one_day_ago:
|
||||
_create_notification(
|
||||
db,
|
||||
audience='user',
|
||||
notif_type='return_day_1',
|
||||
title='Erinnerung: Rueckgabe nach 1 Tag',
|
||||
message=_build_reminder_message(item_name, start_dt=start_dt, end_dt=end_dt),
|
||||
target_user=username,
|
||||
reference={'borrow_id': borrow_id, 'item_id': item_id, 'event': 'day_1'},
|
||||
unique_key=f'reminder:day1:{borrow_id}',
|
||||
severity='warning',
|
||||
audience='admin',
|
||||
notif_type='admin_return_day_1',
|
||||
title='Admin-Info: Ausleihe über 1 Tag aktiv',
|
||||
message=f'Nutzer {display_user} hat das Medium "{item_name}" seit über einem Tag ausgeliehen.',
|
||||
target_user=None,
|
||||
reference={'borrow_id': borrow_id, 'item_id': item_id, 'user': username, 'event': 'day_1'},
|
||||
unique_key=f'admin_reminder:day1:{borrow_id}',
|
||||
severity='info',
|
||||
)
|
||||
|
||||
if isinstance(end_dt, datetime.datetime) and end_dt <= now:
|
||||
_create_notification(
|
||||
db,
|
||||
audience='user',
|
||||
notif_type='return_after_end',
|
||||
title='Erinnerung: Geplante Ausleihe ist beendet',
|
||||
message=_build_reminder_message(item_name, start_dt=start_dt, end_dt=end_dt),
|
||||
target_user=username,
|
||||
reference={'borrow_id': borrow_id, 'item_id': item_id, 'event': 'after_end'},
|
||||
unique_key=f'reminder:end:{borrow_id}',
|
||||
audience='admin',
|
||||
notif_type='admin_return_after_end',
|
||||
title='Admin-Info: Geplante Ausleihe überfällig',
|
||||
message=f'Die Ausleihe von "{item_name}" durch {display_user} hat das geplante Enddatum überschritten.',
|
||||
target_user=None,
|
||||
reference={'borrow_id': borrow_id, 'item_id': item_id, 'user': username, 'event': 'after_end'},
|
||||
unique_key=f'admin_reminder:end:{borrow_id}',
|
||||
severity='warning',
|
||||
)
|
||||
except Exception as exc:
|
||||
app.logger.warning(f"Reminder creation failed: {exc}")
|
||||
if 'app' in globals():
|
||||
app.logger.warning(f"Admin reminder creation failed: {exc}")
|
||||
else:
|
||||
print(f"Admin reminder creation failed: {exc}")
|
||||
finally:
|
||||
if client:
|
||||
client.close()
|
||||
@@ -3618,7 +3626,7 @@ def generate_test_ausleihen():
|
||||
|
||||
test_ausleihungen = [
|
||||
{
|
||||
"User": user_val_1,
|
||||
"User": encrypt_text(user_val_1),
|
||||
"Item": str(item1_res.inserted_id),
|
||||
"Status": "active",
|
||||
"DueDate": due_date_stufe1,
|
||||
@@ -3626,7 +3634,7 @@ def generate_test_ausleihen():
|
||||
"LastUpdated": current_time
|
||||
},
|
||||
{
|
||||
"User": user_val_2,
|
||||
"User": encrypt_text(user_val_2),
|
||||
"Item": str(item2_res.inserted_id),
|
||||
"Status": "active",
|
||||
"DueDate": due_date_stufe2,
|
||||
@@ -3634,7 +3642,7 @@ def generate_test_ausleihen():
|
||||
"LastUpdated": due_date_stufe2
|
||||
},
|
||||
{
|
||||
"User": user_val_3,
|
||||
"User": encrypt_text(user_val_3),
|
||||
"Item": str(item3_res.inserted_id),
|
||||
"Status": "active",
|
||||
"DueDate": due_date_frisch,
|
||||
|
||||
Reference in New Issue
Block a user