manager: check time period start/end are in correct order (#31418)
This commit is contained in:
parent
18cca83798
commit
4e1f9f3f4e
|
@ -99,6 +99,11 @@ class TimePeriodAddForm(forms.Form):
|
|||
start_time = forms.TimeField(label=_('Start Time'), widget=widgets.TimeWidget())
|
||||
end_time = forms.TimeField(label=_('End Time'), widget=widgets.TimeWidget())
|
||||
|
||||
def clean_end_time(self):
|
||||
if self.cleaned_data['end_time'] <= self.cleaned_data['start_time']:
|
||||
raise ValidationError(_('End time must come after start time.'))
|
||||
return self.cleaned_data['end_time']
|
||||
|
||||
|
||||
class TimePeriodForm(forms.ModelForm):
|
||||
class Meta:
|
||||
|
@ -110,6 +115,11 @@ class TimePeriodForm(forms.ModelForm):
|
|||
}
|
||||
exclude = []
|
||||
|
||||
def clean_end_time(self):
|
||||
if self.cleaned_data['end_time'] <= self.cleaned_data['start_time']:
|
||||
raise ValidationError(_('End time must come after start time.'))
|
||||
return self.cleaned_data['end_time']
|
||||
|
||||
|
||||
class NewDeskForm(forms.ModelForm):
|
||||
class Meta:
|
||||
|
|
|
@ -676,6 +676,14 @@ def test_meetings_agenda_add_time_period(app, admin_user):
|
|||
assert u'Wednesday / 10 a.m. → 5 p.m.' in resp.text
|
||||
assert resp.text.index('Monday') < resp.text.index('Wednesday')
|
||||
|
||||
# invert start and end
|
||||
resp2 = resp.click('Add a time period', index=0)
|
||||
resp2.form['weekdays-0'].checked = True
|
||||
resp2.form['start_time'] = '13:00'
|
||||
resp2.form['end_time'] = '10:00'
|
||||
resp2 = resp2.form.submit()
|
||||
assert 'End time must come after start time.' in resp2.text
|
||||
|
||||
# and edit
|
||||
resp = resp.click(u'Wednesday / 10 a.m. → 5 p.m.')
|
||||
assert 'Edit Time Period' in resp.text
|
||||
|
@ -684,6 +692,12 @@ def test_meetings_agenda_add_time_period(app, admin_user):
|
|||
resp = resp.follow()
|
||||
assert TimePeriod.objects.get(desk=desk, weekday=2).start_time.hour == 9
|
||||
|
||||
# and edit with inverted start/end
|
||||
resp2 = resp.click(u'Wednesday / 9 a.m. → 5 p.m.')
|
||||
resp2.form['start_time'] = '18:00'
|
||||
resp2 = resp2.form.submit()
|
||||
assert 'End time must come after start time.' in resp2.text
|
||||
|
||||
# and add same time periods on multiple days
|
||||
resp = resp.click('Add a time period', index=0)
|
||||
resp.form['weekdays-4'].checked = True
|
||||
|
|
Loading…
Reference in New Issue