This commit is contained in:
+19
-8
@@ -7990,8 +7990,12 @@ def check_availability():
|
|||||||
items_col = db['items']
|
items_col = db['items']
|
||||||
|
|
||||||
# Collect potential conflicts (planned and active) for this day
|
# Collect potential conflicts (planned and active) for this day
|
||||||
same_day_start = datetime.datetime.combine(booking_date.date(), datetime.time.min)
|
same_day_start = datetime.datetime.combine(
|
||||||
same_day_end = datetime.datetime.combine(booking_date.date(), datetime.time.max)
|
booking_date.date(), datetime.time.min, tzinfo=ZoneInfo("Europe/Berlin")
|
||||||
|
)
|
||||||
|
same_day_end = datetime.datetime.combine(
|
||||||
|
booking_date.date(), datetime.time.max, tzinfo=ZoneInfo("Europe/Berlin")
|
||||||
|
)
|
||||||
candidates = list(ausleihungen.find({
|
candidates = list(ausleihungen.find({
|
||||||
'Item': item_id,
|
'Item': item_id,
|
||||||
'Status': {'$in': ['planned', 'active']},
|
'Status': {'$in': ['planned', 'active']},
|
||||||
@@ -8009,6 +8013,8 @@ def check_availability():
|
|||||||
if r_start is None:
|
if r_start is None:
|
||||||
r_start = same_day_start
|
r_start = same_day_start
|
||||||
# Overlap check: req_start < r_end and req_end > r_start
|
# Overlap check: req_start < r_end and req_end > r_start
|
||||||
|
r_start = au.ensure_timezone_aware(r_start)
|
||||||
|
r_end = au.ensure_timezone_aware(r_end)
|
||||||
if req_start < r_end and req_end > r_start:
|
if req_start < r_end and req_end > r_start:
|
||||||
conflicts.append({
|
conflicts.append({
|
||||||
'id': str(r.get('_id')),
|
'id': str(r.get('_id')),
|
||||||
@@ -8223,16 +8229,19 @@ def add_booking():
|
|||||||
period = request.form.get('period')
|
period = request.form.get('period')
|
||||||
notes = request.form.get('notes', '')
|
notes = request.form.get('notes', '')
|
||||||
|
|
||||||
# Parse dates as naive datetime objects
|
# Form timestamps represent local school time.
|
||||||
try:
|
try:
|
||||||
# Simple datetime parsing without timezone
|
|
||||||
if start_date_str:
|
if start_date_str:
|
||||||
start_date = datetime.datetime.strptime(start_date_str, '%Y-%m-%d %H:%M:%S')
|
start_date = datetime.datetime.strptime(
|
||||||
|
start_date_str, '%Y-%m-%d %H:%M:%S'
|
||||||
|
).replace(tzinfo=ZoneInfo("Europe/Berlin"))
|
||||||
else:
|
else:
|
||||||
return jsonify({'success': False, 'error': 'Missing start date'})
|
return jsonify({'success': False, 'error': 'Missing start date'})
|
||||||
|
|
||||||
if end_date_str:
|
if end_date_str:
|
||||||
end_date = datetime.datetime.strptime(end_date_str, '%Y-%m-%d %H:%M:%S')
|
end_date = datetime.datetime.strptime(
|
||||||
|
end_date_str, '%Y-%m-%d %H:%M:%S'
|
||||||
|
).replace(tzinfo=ZoneInfo("Europe/Berlin"))
|
||||||
else:
|
else:
|
||||||
end_date = None
|
end_date = None
|
||||||
|
|
||||||
@@ -11274,12 +11283,14 @@ def get_period_times(booking_date, period_num):
|
|||||||
# Create datetime objects for start and end times
|
# Create datetime objects for start and end times
|
||||||
start_datetime = datetime.datetime.combine(
|
start_datetime = datetime.datetime.combine(
|
||||||
booking_date.date(),
|
booking_date.date(),
|
||||||
datetime.time(start_hour, start_min)
|
datetime.time(start_hour, start_min),
|
||||||
|
tzinfo=ZoneInfo("Europe/Berlin")
|
||||||
)
|
)
|
||||||
|
|
||||||
end_datetime = datetime.datetime.combine(
|
end_datetime = datetime.datetime.combine(
|
||||||
booking_date.date(),
|
booking_date.date(),
|
||||||
datetime.time(end_hour, end_min)
|
datetime.time(end_hour, end_min),
|
||||||
|
tzinfo=ZoneInfo("Europe/Berlin")
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ def _get_client():
|
|||||||
return MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
|
return MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
|
||||||
# Add this helper function after imports
|
# Add this helper function after imports
|
||||||
def ensure_timezone_aware(dt):
|
def ensure_timezone_aware(dt):
|
||||||
"""Ensures a datetime is timezone-aware, using UTC if naive"""
|
"""Return a timezone-aware datetime, treating naive DB values as UTC."""
|
||||||
if dt is None:
|
if dt is None:
|
||||||
return None
|
return None
|
||||||
if dt.tzinfo is None:
|
if dt.tzinfo is None:
|
||||||
# Treat naive datetimes as UTC
|
# PyMongo returns BSON datetimes as naive UTC unless tz_aware is enabled.
|
||||||
return dt.replace(tzinfo=None)
|
return dt.replace(tzinfo=datetime.timezone.utc)
|
||||||
return dt
|
return dt
|
||||||
|
|
||||||
def get_current_status(ausleihung, log_changes=False, user=None):
|
def get_current_status(ausleihung, log_changes=False, user=None):
|
||||||
@@ -82,8 +82,8 @@ def get_current_status(ausleihung, log_changes=False, user=None):
|
|||||||
return 'completed'
|
return 'completed'
|
||||||
|
|
||||||
current_time = datetime.datetime.now(ZoneInfo("Europe/Berlin"))
|
current_time = datetime.datetime.now(ZoneInfo("Europe/Berlin"))
|
||||||
start_time = ausleihung.get('Start')
|
start_time = ensure_timezone_aware(ausleihung.get('Start'))
|
||||||
end_time = ausleihung.get('End')
|
end_time = ensure_timezone_aware(ausleihung.get('End'))
|
||||||
|
|
||||||
# Wenn kein Startdatum vorhanden ist, Status auf 'planned' setzen
|
# Wenn kein Startdatum vorhanden ist, Status auf 'planned' setzen
|
||||||
if not start_time:
|
if not start_time:
|
||||||
|
|||||||
Reference in New Issue
Block a user