general: don't allow booking past the event date (#14513)

This commit is contained in:
Frédéric Péters 2017-01-20 10:35:44 +01:00
parent f4a7564058
commit 51bbc55b7f
3 changed files with 21 additions and 1 deletions

View File

@ -199,6 +199,10 @@ class Event(models.Model):
if self.agenda.maximal_booking_delay and (
now().date() <= (self.start_datetime - datetime.timedelta(days=self.agenda.maximal_booking_delay)).date()):
return False
if self.start_datetime < now():
# past the event date, we may want in the future to allow for some
# extra late booking but it's forbidden for now.
return False
return True
@property

View File

@ -65,7 +65,12 @@ class Datetimes(GenericAPIView):
raise APIException('not an events agenda')
kwargs = {}
kwargs['start_datetime__gte'] = (now() + datetime.timedelta(days=agenda.minimal_booking_delay)).date()
if agenda.minimal_booking_delay:
kwargs['start_datetime__gte'] = (now() + datetime.timedelta(days=agenda.minimal_booking_delay)).date()
else:
# if there's no minimal booking delay we still don't want to allow
# booking for past events.
kwargs['start_datetime__gte'] = now()
if agenda.maximal_booking_delay:
kwargs['start_datetime__lt'] = (now() + datetime.timedelta(days=agenda.maximal_booking_delay)).date()

View File

@ -57,6 +57,17 @@ def test_event_bookable_period():
agenda.maximal_booking_delay = 20
assert event.in_bookable_period() is True
# special case for events that happens today
agenda.minimal_booking_delay = 0
agenda.save()
event = Event(start_datetime=now() + datetime.timedelta(minutes=10), places=10, agenda=agenda)
event.save()
assert event.in_bookable_period() is True
event = Event(start_datetime=now() - datetime.timedelta(minutes=10), places=10, agenda=agenda)
event.save()
assert event.in_bookable_period() is False
def test_meeting_type_slug_migration():
executor = MigrationExecutor(connection)
migrate_from = [('agendas', '0011_meetingtype_slug')]