impolementation of standardised time zone
Release Inventarsystem / release-docker (push) Successful in 2m17s

This commit is contained in:
2026-08-23 11:29:42 +02:00
parent 65fadf7f5f
commit 0f0f0ebefd
+14 -13
View File
@@ -33,6 +33,7 @@ import json
import Web.modules.database.settings as cfg import Web.modules.database.settings as cfg
from Web.modules.database.settings import MongoClient from Web.modules.database.settings import MongoClient
import Web.modules.inventarsystem.data_protection as dp import Web.modules.inventarsystem.data_protection as dp
import Web.modules.database.user as us
def _get_client(): def _get_client():
@@ -79,7 +80,7 @@ def get_current_status(ausleihung, log_changes=False, user=None):
if original_status == 'completed': if original_status == 'completed':
return 'completed' return 'completed'
current_time = datetime.datetime.now() current_time = datetime.datetime.now(ZoneInfo("Europe/Berlin"))
start_time = ausleihung.get('Start') start_time = ausleihung.get('Start')
end_time = ausleihung.get('End') end_time = ausleihung.get('End')
@@ -137,7 +138,7 @@ def create_backup_database():
os.makedirs(backup_dir) os.makedirs(backup_dir)
# Aktuelles Datum für den Dateinamen # Aktuelles Datum für den Dateinamen
current_date = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') current_date = datetime.datetime.now(ZoneInfo("Europe/Berlin")).strftime('%Y-%m-%d_%H-%M-%S')
backup_file = os.path.join(backup_dir, f'ausleihungen_backup_{current_date}.json') backup_file = os.path.join(backup_dir, f'ausleihungen_backup_{current_date}.json')
# Ausleihungen abrufen und als JSON speichern # Ausleihungen abrufen und als JSON speichern
@@ -175,7 +176,7 @@ def create_backup_database():
log_file = os.path.join(log_dir, 'ausleihungen_error.log') log_file = os.path.join(log_dir, 'ausleihungen_error.log')
with open(log_file, 'a', encoding='utf-8') as f: with open(log_file, 'a', encoding='utf-8') as f:
f.write(f"{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}: Backup-Fehler: {str(e)}\n") f.write(f"{datetime.datetime.now(ZoneInfo("Europe/Berlin")).strftime('%Y-%m-%d_%H-%M-%S')}: Backup-Fehler: {str(e)}\n")
print(f"Fehler beim Erstellen des Backups: {e}") print(f"Fehler beim Erstellen des Backups: {e}")
return False return False
@@ -204,7 +205,7 @@ def add_ausleihung(item_id, user, start_date, end_date=None, notes="", status="a
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT) client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
db = client[cfg.MONGODB_DB] db = client[cfg.MONGODB_DB]
ausleihungen = db['ausleihungen'] ausleihungen = db['ausleihungen']
ausleihung = { ausleihung = {
'Item': item_id, 'Item': item_id,
'User': dp.encrypt_text(user), 'User': dp.encrypt_text(user),
@@ -270,7 +271,7 @@ def update_ausleihung(id, item_id=None, user_id=None, start=None, end=None, note
return True return True
# UTC Zeitstempel nutzen # UTC Zeitstempel nutzen
update_data['LastUpdated'] = datetime.datetime.now(datetime.timezone.utc) update_data['LastUpdated'] = datetime.datetime.now(ZoneInfo("Europe/Berlin"))
result = ausleihungen.update_one( result = ausleihungen.update_one(
{'_id': doc_id}, {'_id': doc_id},
@@ -300,7 +301,7 @@ def complete_ausleihung(id, end_time=None):
""" """
try: try:
if end_time is None: if end_time is None:
end_time = datetime.datetime.now() end_time = datetime.datetime.now(ZoneInfo("Europe/Berlin"))
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT) client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
db = client[cfg.MONGODB_DB] db = client[cfg.MONGODB_DB]
@@ -312,7 +313,7 @@ def complete_ausleihung(id, end_time=None):
{'$set': { {'$set': {
'End': end_time, 'End': end_time,
'Status': 'completed', 'Status': 'completed',
'LastUpdated': datetime.datetime.now() 'LastUpdated': datetime.datetime.now(ZoneInfo("Europe/Berlin"))
}} }}
) )
@@ -320,7 +321,7 @@ def complete_ausleihung(id, end_time=None):
{'_id': ObjectId(id)}, {'_id': ObjectId(id)},
{'$set': { {'$set': {
'Verfuegbar': True, 'Verfuegbar': True,
'LastUpdated': datetime.datetime.now() 'LastUpdated': datetime.datetime.now(ZoneInfo("Europe/Berlin"))
}} }}
) )
@@ -351,7 +352,7 @@ def cancel_ausleihung(id):
{'_id': ObjectId(id)}, {'_id': ObjectId(id)},
{'$set': { {'$set': {
'Status': 'cancelled', 'Status': 'cancelled',
'LastUpdated': datetime.datetime.now() 'LastUpdated': datetime.datetime.now(ZoneInfo("Europe/Berlin"))
}} }}
) )
@@ -376,7 +377,7 @@ def remove_ausleihung(id):
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT) client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
db = client[cfg.MONGODB_DB] db = client[cfg.MONGODB_DB]
ausleihungen = db['ausleihungen'] ausleihungen = db['ausleihungen']
now = datetime.datetime.now() now = datetime.datetime.now(ZoneInfo("Europe/Berlin"))
result = ausleihungen.update_one( result = ausleihungen.update_one(
{'_id': ObjectId(id), 'Status': {'$ne': 'deleted'}}, {'_id': ObjectId(id), 'Status': {'$ne': 'deleted'}},
{'$set': { {'$set': {
@@ -770,7 +771,7 @@ def activate_ausleihung(id):
{'_id': doc_id, 'Status': 'planned'}, {'_id': doc_id, 'Status': 'planned'},
{'$set': { {'$set': {
'Status': 'active', 'Status': 'active',
'LastUpdated': datetime.datetime.now(datetime.timezone.utc) 'LastUpdated': datetime.datetime.now(ZoneInfo("Europe/Berlin"))
}} }}
) )
return result.modified_count > 0 return result.modified_count > 0
@@ -794,7 +795,7 @@ def reset_item_completely(item_id):
return {'success': False, 'message': 'Item nicht gefunden'} return {'success': False, 'message': 'Item nicht gefunden'}
item_name = item.get('Name', 'Unbekannt') item_name = item.get('Name', 'Unbekannt')
now_utc = datetime.datetime.now(datetime.timezone.utc) now_utc = datetime.datetime.now(ZoneInfo("Europe/Berlin"))
# 1. Bulk update active borrowings # 1. Bulk update active borrowings
update_res = ausleihungen_collection.update_many( update_res = ausleihungen_collection.update_many(
@@ -862,7 +863,7 @@ def mark_booking_active(booking_id, ausleihung_id=None):
doc_id = ObjectId(booking_id) if isinstance(booking_id, str) else booking_id doc_id = ObjectId(booking_id) if isinstance(booking_id, str) else booking_id
update_data = { update_data = {
'Status': 'active', 'Status': 'active',
'LastUpdated': datetime.datetime.now(datetime.timezone.utc) 'LastUpdated': datetime.datetime.now(ZoneInfo("Europe/Berlin"))
} }
if ausleihung_id: if ausleihung_id:
update_data['AusleihungId'] = ausleihung_id update_data['AusleihungId'] = ausleihung_id