manager: don't crash on empty "time period exception" dialog (#20461)

This commit is contained in:
Frédéric Péters 2017-12-11 17:02:15 +01:00
parent 588c5952fe
commit dd9274fd05
2 changed files with 7 additions and 0 deletions

View File

@ -542,6 +542,9 @@ class TimePeriodException(models.Model):
raise ValidationError(_('One or several bookings exists within this time slot.'))
def has_booking_within_time_slot(self):
if not (self.start_datetime and self.end_datetime):
# incomplete time period, can't tell
return False
for event in Event.objects.filter(agenda=self.desk.agenda,
booking__isnull=False,
booking__cancellation_datetime__isnull=True):

View File

@ -782,6 +782,10 @@ def test_meetings_agenda_add_time_period_exception_when_booking_exists(app, admi
login(app)
resp = app.get('/manage/agendas/%d/' % agenda.pk)
resp = resp.click('Add a time period exception')
resp = resp.form.submit() # submit empty form
# fields should be marked with errors
assert resp.body.count('This field is required.') == 2
# try again with data in fields
resp.form['start_datetime'] = '2017-05-22 08:00'
resp.form['end_datetime'] = '2017-05-26 17:30'
resp = resp.form.submit()