Profile.set_next_nag_date does not touch already set dates.

This commit is contained in:
Pēteris Caune 2017-10-15 21:43:48 +03:00
parent 5c64e0cd5d
commit 2a7ee66d1e
2 changed files with 4 additions and 4 deletions

View File

@ -203,8 +203,8 @@ class Profile(models.Model):
is_member = models.Q(user__memberships__team=self) is_member = models.Q(user__memberships__team=self)
q = Profile.objects.filter(is_owner | is_member) q = Profile.objects.filter(is_owner | is_member)
q = q.exclude(nag_period=NO_NAG) q = q.exclude(nag_period=NO_NAG)
# Exclude profiles with next_nag_date in future # Exclude profiles with next_nag_date already set
q = q.exclude(next_nag_date__gt=timezone.now()) q = q.filter(next_nag_date__isnull=True)
q.update(next_nag_date=timezone.now() + models.F("nag_period")) q.update(next_nag_date=timezone.now() + models.F("nag_period"))

View File

@ -122,8 +122,8 @@ class SendAlertsTestCase(BaseTestCase):
self.bobs_profile.refresh_from_db() self.bobs_profile.refresh_from_db()
self.assertIsNotNone(self.bobs_profile.next_nag_date) self.assertIsNotNone(self.bobs_profile.next_nag_date)
def test_it_does_not_touch_future_next_nag_dates(self): def test_it_does_not_touch_already_set_next_nag_dates(self):
original_nag_date = now() + timedelta(minutes=30) original_nag_date = now() - timedelta(minutes=30)
self.profile.nag_period = timedelta(hours=1) self.profile.nag_period = timedelta(hours=1)
self.profile.next_nag_date = original_nag_date self.profile.next_nag_date = original_nag_date
self.profile.save() self.profile.save()