1. pombredanne
  2. cciw-website

Commits

Luke Plant  committed e9b8906

Corrected booking warning email to only be sent out once

(Assuming hourly cron job)

  • Participants
  • Parent commits d13649b
  • Branches bookings

Comments (0)

Files changed (2)

File cciw/bookings/management/commands/expire_bookings.py

View file
     def handle(self, *args, **options):
 
         now = datetime.now()
-        nowplus12h = now + timedelta(0.5)
+
+        # For the warning, we send out between 12 and 13 hours before booking
+        # expires.  This relies on this job being run once an hour, and only
+        # once an hour.
+        nowplus12h = now + timedelta(0, 3600 * 12)
+        nowplus13h = now + timedelta(0, 3600 * 13)
 
         unconfirmed = Booking.objects.unconfirmed().order_by('account')
-        to_warn = unconfirmed.filter(booking_expires__lt=nowplus12h)
-        to_expire = unconfirmed.filter(booking_expires__lt=now)
+        to_warn = unconfirmed.filter(booking_expires__lte=nowplus13h,
+                                     booking_expires__gte=nowplus12h)
+        to_expire = unconfirmed.filter(booking_expires__lte=now)
 
-        # We do the 'to_expire' first, so we don't warn those that have already
-        # expired (works since query sets are lazy)
         for booking_set, expired in [(to_expire, True),
                                      (to_warn, False)]:
             groups = []

File cciw/bookings/tests.py

View file
         acc = self.get_account()
         book_basket_now(acc.bookings.basket(get_thisyear()))
         b = acc.bookings.all()[0]
-        b.booking_expires = b.booking_expires - timedelta(0.6)
+        b.booking_expires = b.booking_expires - timedelta(0.49)
         b.save()
 
         mail.outbox = []