general: don't allow booking past the event date (#14513)
This commit is contained in:
parent
f4a7564058
commit
51bbc55b7f
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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')]
|
||||
|
|
Loading…
Reference in New Issue