0001-manager-add-exception-on-all-desks-42411.patch
chrono/manager/forms.py | ||
---|---|---|
254 | 254 | |
255 | 255 | |
256 | 256 |
class TimePeriodExceptionForm(forms.ModelForm): |
257 |
all_desks = forms.BooleanField(label=_('Apply exception on all desks of the agenda'), required=False) |
|
258 | ||
257 | 259 |
class Meta: |
258 | 260 |
model = TimePeriodException |
259 | 261 |
fields = ['desk', 'start_datetime', 'end_datetime', 'label'] |
... | ... | |
265 | 267 |
'end_datetime': SplitDateTimeField, |
266 | 268 |
} |
267 | 269 | |
270 |
def __init__(self, *args, **kwargs): |
|
271 |
super().__init__(*args, **kwargs) |
|
272 |
if self.instance.pk is not None: |
|
273 |
del self.fields['all_desks'] |
|
274 | ||
268 | 275 |
def clean(self): |
269 | 276 |
cleaned_data = super().clean() |
270 | 277 |
chrono/manager/views.py | ||
---|---|---|
1653 | 1653 | |
1654 | 1654 |
def form_valid(self, form): |
1655 | 1655 |
result = super().form_valid(form) |
1656 |
if self.object.has_booking_within_time_slot(): |
|
1657 |
message = _('Exception added. Note: one or several bookings exists within this time slot.') |
|
1658 |
messages.info(self.request, message) |
|
1656 |
exceptions = [self.object] |
|
1657 |
if form.cleaned_data['all_desks']: |
|
1658 |
for desk in Desk.objects.filter(agenda=self.object.desk.agenda_id): |
|
1659 |
if desk == self.object.desk: |
|
1660 |
continue |
|
1661 |
exceptions.append( |
|
1662 |
TimePeriodException.objects.create( |
|
1663 |
desk=desk, |
|
1664 |
label=self.object.label, |
|
1665 |
start_datetime=self.object.start_datetime, |
|
1666 |
end_datetime=self.object.end_datetime, |
|
1667 |
) |
|
1668 |
) |
|
1669 |
for exception in exceptions: |
|
1670 |
if exception.has_booking_within_time_slot(): |
|
1671 |
message = ungettext( |
|
1672 |
'Exception added. Note: one or several bookings exists within this time slot.', |
|
1673 |
'Exceptions added. Note: one or several bookings exists within this time slot.', |
|
1674 |
len(exceptions), |
|
1675 |
) |
|
1676 |
messages.info(self.request, message) |
|
1677 |
break |
|
1659 | 1678 |
return result |
1660 | 1679 | |
1661 | 1680 |
tests/test_manager.py | ||
---|---|---|
1913 | 1913 |
assert 'Exception 1' in resp.text |
1914 | 1914 |
assert 'Exception 2' in resp.text |
1915 | 1915 | |
1916 |
# add global time exception |
|
1917 |
agenda2 = Agenda.objects.create(label='Foo bar', kind='meetings') |
|
1918 |
Desk.objects.create(agenda=agenda2, label='Other Desk') # check exception is not created for this one |
|
1919 |
desk2 = Desk.objects.create(agenda=agenda, label='Desk B') |
|
1920 |
event = Event.objects.create( |
|
1921 |
agenda=agenda, places=1, desk=desk2, start_datetime=make_aware(datetime.datetime(2017, 5, 22, 10, 30)) |
|
1922 |
) |
|
1923 |
Booking.objects.create(event=event) |
|
1924 |
resp = app.get('/manage/agendas/%s/desk/%s/add-time-period-exception' % (agenda.pk, desk.pk)) |
|
1925 |
future = tomorrow + datetime.timedelta(days=35) |
|
1926 |
resp.form['label'] = 'Exception 3' |
|
1927 |
resp.form['start_datetime_0'] = '2017-05-22' |
|
1928 |
resp.form['start_datetime_1'] = '08:00' |
|
1929 |
resp.form['end_datetime_0'] = '2017-05-26' |
|
1930 |
resp.form['end_datetime_1'] = '17:30' |
|
1931 |
resp.form['all_desks'] = True |
|
1932 |
resp = resp.form.submit().follow() |
|
1933 |
assert TimePeriodException.objects.count() == 4 |
|
1934 |
assert 'Exceptions added. Note: one or several bookings exists within this time slot.' in resp.text |
|
1935 | ||
1936 |
exception = TimePeriodException.objects.first() |
|
1937 |
resp = app.get('/manage/time-period-exceptions/%s/edit' % exception.pk) |
|
1938 |
assert 'all_desks' not in resp.context['form'].fields |
|
1939 | ||
1916 | 1940 | |
1917 | 1941 |
def test_meetings_agenda_add_time_period_exception_when_booking_exists(app, admin_user): |
1918 | 1942 |
agenda = Agenda.objects.create(label='Foo bar', kind='meetings') |
1919 |
- |