Files
KeepItGoingServer/notifications/models.py
T
Keith SmithandClaude Sonnet 4.5 aca8abca56 Fix daily email timing to work across all timezones
Critical fix: Task now runs every hour instead of once at 6 AM UTC.
This ensures users in all timezones receive their email at 6 AM local time.

Changes:
- Run task every hour instead of once daily
- Check if it's 6-7 AM in user's timezone (1 hour window)
- Track sent emails in Notification model to prevent duplicates
- Add 'daily_email' notification type

Without this fix, users in timezones where 6 AM UTC is not morning
would never receive their daily email.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-09 09:34:39 -07:00

72 lines
2.0 KiB
Python

"""
Notification models for KeepItGoing.
"""
import uuid
from django.conf import settings
from django.db import models
class Notification(models.Model):
"""
Stores notifications for users.
"""
NOTIFICATION_TYPES = [
('reminder', 'Task Reminder'),
('due_soon', 'Due Soon'),
('overdue', 'Overdue'),
('shared', 'Task Shared'),
('comment', 'Comment'),
('daily_email', 'Daily Email'),
]
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name='notifications'
)
notification_type = models.CharField(max_length=20, choices=NOTIFICATION_TYPES)
title = models.CharField(max_length=255)
message = models.TextField()
task = models.ForeignKey(
'tasks.Task',
on_delete=models.CASCADE,
null=True,
blank=True,
related_name='notifications'
)
is_read = models.BooleanField(default=False)
read_at = models.DateTimeField(null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
db_table = 'notifications'
ordering = ['-created_at']
def __str__(self):
return f"{self.notification_type}: {self.title}"
class ScheduledReminder(models.Model):
"""
Tracks scheduled reminders for tasks.
"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
task = models.ForeignKey(
'tasks.Task',
on_delete=models.CASCADE,
related_name='scheduled_reminders'
)
remind_at = models.DateTimeField()
is_sent = models.BooleanField(default=False)
sent_at = models.DateTimeField(null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
db_table = 'scheduled_reminders'
ordering = ['remind_at']
def __str__(self):
return f"Reminder for {self.task.title} at {self.remind_at}"