notifications.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import logging
  2. # Configure logging
  3. logging.basicConfig(level=logging.INFO)
  4. logger = logging.getLogger("notifications")
  5. EMAIL_TEMPLATES = {
  6. "en": {
  7. "status_change_subject": "Radionica3D: Update on your Order #{order_id}",
  8. "status_change_body": "Hello {first_name},\n\nYour order status has been updated to: {new_status}.\n\nCheck details here: http://localhost:5173/orders"
  9. },
  10. "ru": {
  11. "status_change_subject": "Radionica3D: Обновление по вашему заказу #{order_id}",
  12. "status_change_body": "Здравствуйте, {first_name},\n\nСтатус вашего заказа обновлен на: {new_status}.\n\nПодробности по ссылке: http://localhost:5173/orders"
  13. },
  14. "me": {
  15. "status_change_subject": "Radionica3D: Ažuriranje vaše narudžbe #{order_id}",
  16. "status_change_body": "Zdravo {first_name},\n\nStatus vaše narudžbe je ažuriran na: {new_status}.\n\nDetalje provjerite ovdje: http://localhost:5173/orders"
  17. },
  18. "ua": {
  19. "status_change_subject": "Radionica3D: Оновлення вашого замовлення #{order_id}",
  20. "status_change_body": "Вітаємо, {first_name},\n\nСтатус вашого замовлення оновлено на: {new_status}.\n\nДеталі за посиланням: http://localhost:5173/orders"
  21. }
  22. }
  23. def send_email(to_email: str, subject: str, body: str):
  24. """
  25. Mock function for sending emails. Users will configure SMTP here.
  26. """
  27. pass
  28. def notify_status_change(email: str, order_id: int, new_status: str, first_name: str, lang: str = "en"):
  29. """
  30. Hook to send notification when order status changes.
  31. The USER will configure SMTP here later.
  32. """
  33. logger.info(f"NOTIFICATION HOOK: Sending status update to {email} for Order #{order_id}. New Status: {new_status} (Lang: {lang})")
  34. lang = lang.lower() if lang else "en"
  35. if lang not in EMAIL_TEMPLATES:
  36. lang = "en"
  37. templates = EMAIL_TEMPLATES[lang]
  38. subject = templates["status_change_subject"].format(order_id=order_id)
  39. body = templates["status_change_body"].format(
  40. first_name=first_name,
  41. new_status=new_status
  42. )
  43. # send_email(email, subject, body)
  44. return True