1 from datetime import timedelta
2 from django.utils.timezone import now
3 from django.utils.translation import ugettext_lazy as _
4 from .recipient import Recipient
8 allow_negative_offset = False
12 def __init__(self, time=None, min_days_since=None, max_days_since=None):
13 self.time = time or now()
14 self.min_days_since = min_days_since
15 self.max_days_since = max_days_since
17 def get_recipients(self):
19 self.get_recipient(obj)
20 for obj in self.get_objects()
23 def get_recipient(self, obj):
25 hash_value=self.get_hash_value(obj),
26 email=self.get_email(obj),
27 context=self.get_context(obj),
30 def get_example_recipient(self, email):
31 return self.get_recipient(
32 self.get_example_object(email)
35 def get_example_object(self, email):
36 from club.models import Schedule
42 payed_at=n - timedelta(2),
43 started_at=n - timedelta(1),
44 expires_at=n + timedelta(1),
47 def get_objects(self):
50 def get_hash_value(self, obj):
53 def get_email(self, obj):
56 def get_context(self, obj):
58 obj._meta.model_name: obj,
63 class ClubSingle(State):
65 name = _('club one-time donors')
68 class ClubSingleExpired(State):
69 slug = 'club-membership-expiring'
70 allow_negative_offset = True
71 name = _('club one-time donors with donation expiring')
73 def get_objects(self):
74 from club.models import Schedule
75 return Schedule.objects.filter(
77 expires_at__lt=self.time - self.offset
80 def get_hashed_value(self, obj):
81 return '%s:%s' % (obj.pk, obj.expires_at.isoformat())
84 class ClubTried(State):
85 slug = 'club-payment-unfinished'
86 name = _('club would-be donors')
88 def get_objects(self):
89 from club.models import Schedule
90 return Schedule.objects.filter(
92 started_at__lt=self.time - self.offset,
96 class ClubRecurring(State):
97 slug = 'club-recurring'
98 name = _('club recurring donors')
101 class ClubRecurringExpired(State):
102 slug = 'club-recurring-payment-problem'
103 name = _('club recurring donors with donation expired')
105 def get_objects(self):
106 from club.models import Schedule
107 return Schedule.objects.none()
112 name = _('cold group')
121 ClubRecurringExpired,