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, offset=0, time=None):
13 self.time = time or now()
14 if isinstance(offset, int):
15 offset = timedelta(offset)
18 def get_recipients(self):
21 hash_value=self.get_hash_value(obj),
22 email=self.get_email(obj),
23 context=self.get_context(obj),
25 for obj in self.get_objects()
28 def get_objects(self):
31 def get_hash_value(self, obj):
34 def get_email(self, obj):
37 def get_context(self, obj):
39 obj._meta.model_name: obj,
44 class ClubMembershipExpiring(State):
45 slug = 'club-membership-expiring'
46 allow_negative_offset = True
47 name = _('club membership expiring')
49 def get_objects(self):
50 from club.models import Schedule
51 return Schedule.objects.filter(
53 expires_at__lt=self.time - self.offset
56 def get_hashed_value(self, obj):
57 return '%s:%s' % (obj.pk, obj.expires_at.isoformat())
59 class ClubPaymentUnfinished(State):
60 slug = 'club-payment-unfinished'
61 name = _('club payment unfinished')
63 def get_objects(self):
64 from club.models import Schedule
65 return Schedule.objects.filter(
67 started_at__lt=self.time - self.offset,
72 ClubMembershipExpiring,
73 ClubPaymentUnfinished,