- if isinstance(offset, int):
- offset = timedelta(offset)
- self.offset = offset
-
- def get_recipients(self):
- return [
- Recipient(
- hash_value=self.get_hash_value(obj),
- email=self.get_email(obj),
- context=self.get_context(obj),
+ self.min_days_since = min_days_since
+ self.max_days_since = max_days_since
+ self.test = test
+
+ def get_contacts(self):
+ Contact = apps.get_model('messaging', 'Contact')
+ contacts = Contact.objects.filter(level=self.level)
+
+ if self.min_days_since is not None or self.expired:
+ cutoff = self.time - timedelta(self.min_days_since or 0)
+ if self.expired:
+ contacts = contacts.filter(expires_at__lt=cutoff)
+ else:
+ contacts = contacts.filter(since__lt=cutoff)
+
+ if self.max_days_since is not None:
+ cutoff = self.time - timedelta(self.max_days_since)
+ if self.expired:
+ contacts = contacts.filter(expires_at__gt=cutoff)
+ else:
+ contacts = contacts.filter(since__gt=cutoff)
+
+ if self.expired is False:
+ contacts = contacts.exclude(expires_at__lt=self.time)
+
+ return contacts
+
+ def get_context(self, contact):
+ if self.test:
+ return self.get_example_context(contact)
+
+ Schedule = apps.get_model('club', 'Schedule')
+ schedules = Schedule.objects.filter(email=contact.email)
+ return {
+ "schedule": self.get_schedule(schedules)
+ }
+
+ def get_example_context(self, contact):
+ Schedule = apps.get_model('club', 'Schedule')
+ return {
+ "schedule": Schedule(
+ email=contact.email,
+ key='xxxxxxxxx',
+ amount=100,
+ payed_at=self.time - timedelta(2),
+ started_at=self.time - timedelta(1),
+ expires_at=self.time + timedelta(1),