notification_template.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. """Notification template model for customizable notification messages."""
  2. from datetime import datetime
  3. from sqlalchemy import Boolean, DateTime, Integer, String, Text, func
  4. from sqlalchemy.orm import Mapped, mapped_column
  5. from backend.app.core.database import Base
  6. class NotificationTemplate(Base):
  7. """Model for notification message templates."""
  8. __tablename__ = "notification_templates"
  9. id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
  10. event_type: Mapped[str] = mapped_column(String(50), nullable=False, unique=True)
  11. name: Mapped[str] = mapped_column(String(100), nullable=False)
  12. title_template: Mapped[str] = mapped_column(Text, nullable=False)
  13. body_template: Mapped[str] = mapped_column(Text, nullable=False)
  14. is_default: Mapped[bool] = mapped_column(Boolean, default=True)
  15. created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
  16. updated_at: Mapped[datetime] = mapped_column(
  17. DateTime, server_default=func.now(), onupdate=func.now()
  18. )
  19. # Default templates for seeding
  20. DEFAULT_TEMPLATES = [
  21. {
  22. "event_type": "print_start",
  23. "name": "Print Started",
  24. "title_template": "Print Started",
  25. "body_template": "{printer}: {filename}\nEstimated: {estimated_time}",
  26. },
  27. {
  28. "event_type": "print_complete",
  29. "name": "Print Completed",
  30. "title_template": "Print Completed",
  31. "body_template": "{printer}: {filename}\nTime: {duration}\nFilament: {filament_grams}g",
  32. },
  33. {
  34. "event_type": "print_failed",
  35. "name": "Print Failed",
  36. "title_template": "Print Failed",
  37. "body_template": "{printer}: {filename}\nTime: {duration}\nReason: {reason}",
  38. },
  39. {
  40. "event_type": "print_stopped",
  41. "name": "Print Stopped",
  42. "title_template": "Print Stopped",
  43. "body_template": "{printer}: {filename}\nTime: {duration}",
  44. },
  45. {
  46. "event_type": "print_progress",
  47. "name": "Print Progress",
  48. "title_template": "Print {progress}% Complete",
  49. "body_template": "{printer}: {filename}\nRemaining: {remaining_time}",
  50. },
  51. {
  52. "event_type": "printer_offline",
  53. "name": "Printer Offline",
  54. "title_template": "Printer Offline",
  55. "body_template": "{printer} has disconnected",
  56. },
  57. {
  58. "event_type": "printer_error",
  59. "name": "Printer Error",
  60. "title_template": "Printer Error: {error_type}",
  61. "body_template": "{printer}\n{error_detail}",
  62. },
  63. {
  64. "event_type": "filament_low",
  65. "name": "Filament Low",
  66. "title_template": "Filament Low",
  67. "body_template": "{printer}: Slot {slot} at {remaining_percent}%",
  68. },
  69. {
  70. "event_type": "maintenance_due",
  71. "name": "Maintenance Due",
  72. "title_template": "Maintenance Due",
  73. "body_template": "{printer}:\n{items}",
  74. },
  75. {
  76. "event_type": "test",
  77. "name": "Test Notification",
  78. "title_template": "Bambuddy Test",
  79. "body_template": "This is a test notification. If you see this, notifications are working!",
  80. },
  81. ]