X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ef79260cc592940ed31899db916fb84bd723291c..91eb62bdcc6b891f12d20b1d8d5d70cbd7b12325:/src/messaging/models.py diff --git a/src/messaging/models.py b/src/messaging/models.py index b7a87b35d..c929228f2 100644 --- a/src/messaging/models.py +++ b/src/messaging/models.py @@ -43,7 +43,8 @@ class EmailTemplate(models.Model): contacts = contacts.exclude(emailsent__template=self) for contact in contacts: - self.send(contact, verbose=verbose, dry_run=dry_run) + if not contact.is_annoyed: + self.send(contact, verbose=verbose, dry_run=dry_run) def get_state(self, time=None, test=False): for s in states: @@ -115,6 +116,11 @@ class Contact(models.Model): self.key = get_random_hash(self.email) super().save(*args, **kwargs) + @property + def is_annoyed(self): + cutoff = now() - timedelta(settings.MESSAGING_MIN_DAYS) + return self.emailsent_set.filter(timestamp__gte=cutoff).exists() + def get_optout_url(self): return reverse('messaging_optout', args=[self.key])