0001-agenda-dont-check-for-bookings-on-exception-creation.patch
chrono/agendas/models.py | ||
---|---|---|
1146 | 1146 | |
1147 | 1147 |
return exc_repr |
1148 | 1148 | |
1149 |
def clean(self): |
|
1150 |
super(TimePeriodException, self).clean() |
|
1151 |
if self.has_booking_within_time_slot(): |
|
1152 |
raise ValidationError(_('One or several bookings exists within this time slot.')) |
|
1153 | ||
1154 | 1149 |
def has_booking_within_time_slot(self): |
1155 | 1150 |
if not (self.start_datetime and self.end_datetime): |
1156 | 1151 |
# incomplete time period, can't tell |
chrono/manager/views.py | ||
---|---|---|
1060 | 1060 |
model = TimePeriodException |
1061 | 1061 |
form_class = TimePeriodExceptionForm |
1062 | 1062 | |
1063 |
def form_valid(self, form): |
|
1064 |
result = super().form_valid(form) |
|
1065 |
if self.object.has_booking_within_time_slot(): |
|
1066 |
message = _('One or several bookings exists within this time slot.') |
|
1067 |
messages.info(self.request, message) |
|
1068 |
return result |
|
1069 | ||
1063 | 1070 | |
1064 | 1071 |
agenda_add_time_period_exception = AgendaAddTimePeriodExceptionView.as_view() |
1065 | 1072 |
tests/test_manager.py | ||
---|---|---|
1113 | 1113 |
resp.form['start_datetime$time'] = '08:00' |
1114 | 1114 |
resp.form['end_datetime$date'] = '2017-05-26' |
1115 | 1115 |
resp.form['end_datetime$time'] = '17:30' |
1116 |
resp = resp.form.submit() |
|
1116 |
resp = resp.form.submit().follow()
|
|
1117 | 1117 |
assert 'One or several bookings exists within this time slot.' in resp.text |
1118 |
assert TimePeriodException.objects.count() == 0 |
|
1119 | ||
1120 |
# check it's possible to add an exception on another desk |
|
1121 |
desk = Desk.objects.create(agenda=agenda, label='Desk B') |
|
1122 |
TimePeriod.objects.create( |
|
1123 |
weekday=1, desk=desk, start_time=datetime.time(10, 0), end_time=datetime.time(12, 0) |
|
1124 |
) |
|
1125 |
resp = app.get('/manage/agendas/%d/' % agenda.pk).follow() |
|
1126 |
resp = resp.click('Settings') |
|
1127 |
resp = resp.click('Add a time period exception', href='desk/%s/' % desk.id) |
|
1128 |
resp.form['start_datetime$date'] = '2017-05-22' |
|
1129 |
resp.form['start_datetime$time'] = '08:00' |
|
1130 |
resp.form['end_datetime$date'] = '2017-05-26' |
|
1131 |
resp.form['end_datetime$time'] = '17:30' |
|
1132 |
resp = resp.form.submit() |
|
1133 | 1118 |
assert TimePeriodException.objects.count() == 1 |
1134 | 1119 | |
1135 | 1120 | |
... | ... | |
1154 | 1139 |
resp.form['start_datetime$time'] = '08:00' |
1155 | 1140 |
resp.form['end_datetime$date'] = '2017-05-26' |
1156 | 1141 |
resp.form['end_datetime$time'] = '17:30' |
1157 |
resp = resp.form.submit() |
|
1142 |
resp = resp.form.submit().follow()
|
|
1158 | 1143 |
assert 'One or several bookings exists within this time slot.' not in resp.text |
1159 | 1144 |
assert TimePeriodException.objects.count() == 1 |
1160 | 1145 | |
1161 |
- |