Internal
Public Access
Delay overdue notification an hour, retroactively apply reminder setting
Two refinements from live testing of the reminder feature: - Due-time tasks scheduled "due now" and "overdue" at the exact same moment. Task._due_and_overdue_moments() now delays "overdue" by an hour so they don't arrive together. The overdue badge/styling elsewhere is unaffected - only this notification's timing changes. - Task.reschedule_reminders() only captures user.default_reminder_minutes at the moment a task's own due_date/due_time is set, so changing the profile setting didn't reach tasks whose due date was already set. User.save() now detects a change to that setting and calls the new User.reschedule_reminder_notifications(), which recomputes the "before due" reminder on active due tasks that don't have their own explicit reminder_at override. 8 new/updated tests cover the overdue delay and the retroactive rescheduling (including that unrelated profile saves and tasks with an explicit reminder_at are left untouched). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
a27fcc4c69
commit
f92ce7a3d4
@@ -57,6 +57,39 @@ class User(AbstractUser):
|
||||
def __str__(self):
|
||||
return self.email
|
||||
|
||||
@classmethod
|
||||
def from_db(cls, db, field_names, values):
|
||||
instance = super().from_db(db, field_names, values)
|
||||
instance._loaded_default_reminder_minutes = dict(zip(field_names, values)).get('default_reminder_minutes')
|
||||
return instance
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
loaded_reminder_minutes = getattr(self, '_loaded_default_reminder_minutes', None)
|
||||
reminder_minutes_changed = (
|
||||
loaded_reminder_minutes is not None and loaded_reminder_minutes != self.default_reminder_minutes
|
||||
)
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
self._loaded_default_reminder_minutes = self.default_reminder_minutes
|
||||
|
||||
if reminder_minutes_changed:
|
||||
self.reschedule_reminder_notifications()
|
||||
|
||||
def reschedule_reminder_notifications(self):
|
||||
"""
|
||||
Recompute "before due" reminders for active tasks using the current
|
||||
default_reminder_minutes. Task.reschedule_reminders() only captures
|
||||
this setting at the moment a task's own due_date/due_time is set,
|
||||
so it doesn't apply retroactively on its own - this is what makes a
|
||||
profile-level change to the setting reach existing tasks. Tasks
|
||||
with their own explicit reminder_at override are left alone.
|
||||
"""
|
||||
tasks = self.tasks.filter(
|
||||
due_date__isnull=False, is_deleted=False, reminder_at__isnull=True,
|
||||
).exclude(status__in=('completed', 'cancelled'))
|
||||
for task in tasks:
|
||||
task.reschedule_reminders()
|
||||
|
||||
|
||||
class DeviceToken(models.Model):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user