fnp
/
wolnelektury.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Librarian 1.8
[wolnelektury.git]
/
src
/
messaging
/
models.py
diff --git
a/src/messaging/models.py
b/src/messaging/models.py
index
8ef6c4c
..
c929228
100644
(file)
--- a/
src/messaging/models.py
+++ b/
src/messaging/models.py
@@
-4,6
+4,7
@@
from django.core.mail import send_mail
from django.db import models
from django.template import Template, Context
from django.urls import reverse
from django.db import models
from django.template import Template, Context
from django.urls import reverse
+from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from sentry_sdk import capture_exception
from catalogue.utils import get_random_hash
from django.utils.translation import ugettext_lazy as _
from sentry_sdk import capture_exception
from catalogue.utils import get_random_hash
@@
-40,9
+41,10
@@
class EmailTemplate(models.Model):
state = self.get_state(time=time)
contacts = state.get_contacts()
state = self.get_state(time=time)
contacts = state.get_contacts()
- contacts = contacts.exclude(emailsent_
set_
_template=self)
+ contacts = contacts.exclude(emailsent__template=self)
for contact in contacts:
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:
def get_state(self, time=None, test=False):
for s in states:
@@
-114,6
+116,11
@@
class Contact(models.Model):
self.key = get_random_hash(self.email)
super().save(*args, **kwargs)
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])
def get_optout_url(self):
return reverse('messaging_optout', args=[self.key])
@@
-127,7
+134,9
@@
class Contact(models.Model):
if not created:
obj.ascend(level, since, expires_at)
if not created:
obj.ascend(level, since, expires_at)
- def ascend(self, level, since, expires_at=None):
+ def ascend(self, level, since=None, expires_at=None):
+ if since is None:
+ since = now()
if level < self.level:
return
if level == self.level:
if level < self.level:
return
if level == self.level: