parser.add_argument('--dry-run', action='store_true', help='Dry run')
def handle(self, *args, **options):
- for et in EmailTemplate.objects.filter(is_active=True):
+ for et in EmailTemplate.objects.order_by('min_days_since').filter(is_active=True):
et.run(verbose=True, dry_run=options['dry_run'])
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:
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])