feat: aggiunti: loggica random, tema scuro, correzioni mail, miglioramenti generali, cache;

This commit is contained in:
StefanoSalemi
2026-04-17 18:27:37 +02:00
parent a7ef46640d
commit 104ad53a9a
26 changed files with 861 additions and 216 deletions

View File

@@ -138,6 +138,33 @@ def notify_parking_released(user: "User", assignment_date: date, spot_name: str)
send_email(user.email, subject, body_html)
def notify_parking_released_to_user(user: "User", assignment_date: date, spot_name: str, previous_user_name: str = None):
"""Send notification when a parking spot is granted due to someone else releasing it"""
if not user.notify_parking_changes:
return
day_name = assignment_date.strftime("%d/%m/%Y")
subject = f"Assegnazione Riparatoria - {day_name}"
if previous_user_name:
message = f"Ti è stato ceduto il posto da {previous_user_name} per il giorno {day_name}:"
else:
message = f"Hai ottenuto un posto in ritardo per una rinuncia per il giorno {day_name}:"
body_html = f"""
<html>
<body>
<h2>Posto Auto Assegnato (Rinuncia)</h2>
<p>Ciao {user.name},</p>
<p>{message}</p>
<p style="font-size: 18px; font-weight: bold;">Posto {spot_name}</p>
<p>Cordiali saluti,<br>Team Parking Manager</p>
</body>
</html>
"""
send_email(user.email, subject, body_html)
def notify_parking_reassigned(user: "User", assignment_date: date, spot_name: str, new_user_name: str):
"""Send notification when parking spot is reassigned to someone else"""
if not user.notify_parking_changes:
@@ -225,7 +252,7 @@ def send_presence_reminder(user: "User", next_week_dates: List[date], db: "Sessi
def send_daily_parking_reminder(user: "User", date_obj: datetime, db: "Session") -> bool:
"""Send daily parking reminder for a specific date"""
from database.models import DailyParkingAssignment, NotificationLog
from database.models import DailyParkingAssignment
from services.parking import get_spot_display_name
config.logger.info(f"[SCHEDULER] Checking daily parking reminder for user {user.email}")
@@ -234,19 +261,8 @@ def send_daily_parking_reminder(user: "User", date_obj: datetime, db: "Session")
config.logger.debug(f"[SCHEDULER] User {user.email} has disabled daily parking notifications")
return False
date_str = date_obj.strftime("%Y-%m-%d")
assignment_date = date_obj.date()
# Check if already sent for this date
existing = db.query(NotificationLog).filter(
NotificationLog.user_id == user.id,
NotificationLog.notification_type == NotificationType.DAILY_PARKING,
NotificationLog.reference_date == date_str
).first()
if existing:
return False
# Get parking assignment for this date
assignment = db.query(DailyParkingAssignment).filter(
DailyParkingAssignment.user_id == user.id,
@@ -273,15 +289,6 @@ def send_daily_parking_reminder(user: "User", date_obj: datetime, db: "Session")
"""
if send_email(user.email, subject, body_html):
log = NotificationLog(
id=generate_uuid(),
user_id=user.id,
notification_type=NotificationType.DAILY_PARKING,
reference_date=date_str,
sent_at=datetime.utcnow()
)
db.add(log)
db.commit()
return True
return False
@@ -321,7 +328,7 @@ def run_scheduled_notifications(db: "Session"):
user_minute = user.notify_daily_parking_minute or 0
# Check if it's the right time for this user
if current_hour == user_hour and abs(current_minute - user_minute) < 5:
if current_hour == user_hour and current_minute == user_minute:
config.logger.info(f"[SCHEDULER] Triggering Daily Parking Reminder check for user {user.email} (Scheduled: {user_hour}:{user_minute})")
# Check if Office is OPEN today
is_office_open = True