manager: partial bookings, no delete option if no check object (#82840)

This commit is contained in:
Lauréline Guérin 2023-10-26 10:13:35 +02:00 committed by Valentin Deniaud
parent 61a6bc35bb
commit 81aa0d95fc
2 changed files with 20 additions and 10 deletions

View File

@ -586,13 +586,7 @@ class BookingCheckPresenceForm(forms.Form):
class PartialBookingCheckForm(forms.ModelForm):
presence = forms.NullBooleanField(
label=_('Status'),
widget=forms.RadioSelect(
choices=(
(None, _('Not checked')),
(True, _('Present')),
(False, _('Absent')),
)
),
widget=forms.RadioSelect,
required=False,
)
presence_check_type = forms.ChoiceField(label=_('Type'), required=False)
@ -617,6 +611,13 @@ class PartialBookingCheckForm(forms.ModelForm):
absence_check_types = [(ct.slug, ct.label) for ct in self.check_types if ct.kind == 'absence']
presence_check_types = [(ct.slug, ct.label) for ct in self.check_types if ct.kind == 'presence']
presence_choices = []
if self.instance.pk:
presence_choices.append((None, _('Not checked')))
else:
self.initial['presence'] = True
presence_choices.append((True, _('Present')))
if presence_check_types:
self.fields['presence_check_type'].choices = [(None, '---------')] + presence_check_types
self.fields['presence_check_type'].initial = self.instance.type_slug
@ -632,8 +633,11 @@ class PartialBookingCheckForm(forms.ModelForm):
if not self.instance.booking.start_time:
self.fields['start_time'].widget = widgets.TimeWidget(step=60)
self.fields['end_time'].widget = widgets.TimeWidget(step=60)
self.fields['presence'].widget.choices = ((None, _('Not checked')), (True, _('Present')))
self.fields.pop('absence_check_type', None)
else:
presence_choices.append((False, _('Absent')))
self.fields['presence'].widget.choices = presence_choices
def clean(self):
if self.cleaned_data['end_time'] <= self.cleaned_data['start_time']:

View File

@ -281,9 +281,15 @@ def test_manager_partial_bookings_day_view_multiple_bookings(app, admin_user, fr
resp = resp.click('Booked period', index=0)
resp.form['start_time'] = '09:30'
resp.form['end_time'] = '12:00'
assert resp.form['presence'].options == [('True', True, None), ('False', False, None)]
resp.form['presence'] = 'True'
resp = resp.form.submit().follow()
resp = resp.click('Checked period')
# possible to cancel check is '' option is selected
assert resp.form['presence'].options == [('', False, None), ('True', True, None), ('False', False, None)]
resp = app.get('/manage/agendas/%s/day/%d/%d/%d/' % (agenda.pk, today.year, today.month, today.day))
assert len(resp.pyquery('.partial-booking--registrant')) == 1
assert len(resp.pyquery('.registrant--bar')) == 4
assert len(resp.pyquery('.registrant--bar.check')) == 1
@ -295,6 +301,7 @@ def test_manager_partial_bookings_day_view_multiple_bookings(app, admin_user, fr
resp = resp.click('Booked period')
resp.form['start_time'] = '15:00'
resp.form['end_time'] = '17:00'
assert resp.form['presence'].options == [('True', True, None), ('False', False, None)]
resp.form['presence'] = 'True'
resp = resp.form.submit().follow()
@ -556,8 +563,7 @@ def test_manager_partial_bookings_check_subscription(check_types, app, admin_use
assert 'Fill with booking start time' not in resp.text
assert 'absence_check_type' not in resp.form.fields
assert resp.form['presence'].options == [
('', True, None),
('True', False, None),
('True', True, None),
] # no 'False' option
assert not Booking.objects.exists()