chore(members/tasks): adjust timeframe for crisis list sending

pull/174/head
Christian Merten 3 months ago
parent 9f012eed7a
commit 342227624a
Signed by: christian.merten
GPG Key ID: D953D69721B948B3

@ -1288,6 +1288,23 @@ class Freizeit(CommonModel):
def code(self): def code(self):
return f"B{self.date:%y}-{self.pk}" return f"B{self.date:%y}-{self.pk}"
@staticmethod
def filter_queryset_date_next_n_hours(hours, queryset=None):
if queryset is None:
queryset = Freizeit.objects.all()
return queryset.filter(date__lte=timezone.now() + timezone.timedelta(hours=hours),
date__gte=timezone.now())
@staticmethod
def to_notify_crisis_intervention_list():
qs = Freizeit.objects.filter(notification_crisis_intervention_list_sent=False)
return Freizeit.filter_queryset_date_next_n_hours(48, queryset=qs)
@staticmethod
def to_send_crisis_intervention_list():
qs = Freizeit.objects.filter(crisis_intervention_list_sent=False)
return Freizeit.filter_queryset_date_next_n_hours(24, queryset=qs)
def get_tour_type(self): def get_tour_type(self):
if self.tour_type == FUEHRUNGS_TOUR: if self.tour_type == FUEHRUNGS_TOUR:
return "Führungstour" return "Führungstour"

@ -27,9 +27,7 @@ def send_crisis_intervention_list():
that have not been sent yet. that have not been sent yet.
""" """
no = 0 no = 0
for excursion in Freizeit.objects.filter(date__lt=timezone.now() - timezone.timedelta(days=1), for excursion in Freizeit.to_send_crisis_intervention_list():
date__gt=timezone.now() - timezone.timedelta(days=2)
crisis_intervention_list_sent=False):
excursion.send_crisis_intervention_list() excursion.send_crisis_intervention_list()
no += 1 no += 1
return no return no
@ -42,9 +40,7 @@ def send_notification_crisis_intervention_list():
day and that have not been sent yet. day and that have not been sent yet.
""" """
no = 0 no = 0
for excursion in Freizeit.objects.filter(date__lt=timezone.now() - timezone.timedelta(days=1), for excursion in Freizeit.to_notify_crisis_intervention_list():
date__gt=timezone.now() - timezone.timedelta(days=3),
notification_crisis_intervention_list_sent=False):
excursion.notify_leaders_crisis_intervention_list() excursion.notify_leaders_crisis_intervention_list()
no += 1 no += 1
return no return no

@ -816,6 +816,12 @@ class FreizeitTestCase(BasicMemberTestCase):
self.ex2.jugendleiter.add(self.fritz) self.ex2.jugendleiter.add(self.fritz)
self.st = Statement.objects.create(excursion=self.ex2, night_cost=42, subsidy_to=None) self.st = Statement.objects.create(excursion=self.ex2, night_cost=42, subsidy_to=None)
self.ex2.save() self.ex2.save()
# this excursion is used in the other tests
self.ex3 = Freizeit.objects.create(name='Wild trip 3', kilometers_traveled=120,
tour_type=GEMEINSCHAFTS_TOUR,
tour_approach=MUSKELKRAFT_ANREISE,
difficulty=1,
date=timezone.localtime())
def _setup_test_sjr_application_numbers(self, n_yl, n_b27_local, n_b27_non_local): def _setup_test_sjr_application_numbers(self, n_yl, n_b27_local, n_b27_non_local):
add_memberonlist_by_local(self.ex, n_yl, n_b27_local, n_b27_non_local) add_memberonlist_by_local(self.ex, n_yl, n_b27_local, n_b27_non_local)
@ -968,6 +974,34 @@ class FreizeitTestCase(BasicMemberTestCase):
generate_ljp_vbk(self.ex) generate_ljp_vbk(self.ex)
self.assertIn("Excursion has no LJP proposal", str(cm.exception)) self.assertIn("Excursion has no LJP proposal", str(cm.exception))
def test_filter_queryset_date_next_n_hours(self):
self.ex.date = timezone.now() + timezone.timedelta(hours=12)
self.ex.save()
self.ex2.date = timezone.now() + timezone.timedelta(hours=36)
self.ex2.save()
self.ex3.date = timezone.now() - timezone.timedelta(hours=1)
self.ex3.save()
qs = Freizeit.filter_queryset_date_next_n_hours(24)
self.assertIn(self.ex, qs)
self.assertNotIn(self.ex2, qs)
self.assertNotIn(self.ex3, qs)
def test_querysets_crisis_intervention_list(self):
self.ex.date = timezone.now() + timezone.timedelta(hours=12)
self.ex.crisis_intervention_list_sent = False
self.ex.save()
self.ex2.date = timezone.now() + timezone.timedelta(hours=36)
self.ex2.notification_crisis_intervention_list_sent = False
self.ex2.save()
self.ex3.notification_crisis_intervention_list_sent = True
self.ex3.save()
to_send = Freizeit.to_send_crisis_intervention_list()
to_notify = Freizeit.to_notify_crisis_intervention_list()
self.assertIn(self.ex, to_send)
self.assertNotIn(self.ex2, to_send)
self.assertNotIn(self.ex3, to_send)
self.assertIn(self.ex2, to_notify)
class PDFActionMixin: class PDFActionMixin:
def _test_pdf(self, name, pk, model='freizeit', invalid=False, username='superuser', post_data=None): def _test_pdf(self, name, pk, model='freizeit', invalid=False, username='superuser', post_data=None):

Loading…
Cancel
Save