manager: change partial booking check deletion UI (#82231)

This commit is contained in:
Valentin Deniaud 2023-11-13 17:16:10 +01:00
parent 9b27620a89
commit 8a8bea24a6
3 changed files with 25 additions and 27 deletions

View File

@ -586,7 +586,13 @@ class BookingCheckPresenceForm(forms.Form):
class PartialBookingCheckForm(forms.ModelForm):
presence = forms.NullBooleanField(
label=_('Status'),
widget=forms.RadioSelect,
widget=forms.RadioSelect(
choices=(
(None, _('Not checked')),
(True, _('Present')),
(False, _('Absent')),
)
),
required=False,
)
presence_check_type = forms.ChoiceField(label=_('Type'), required=False)
@ -594,7 +600,7 @@ class PartialBookingCheckForm(forms.ModelForm):
class Meta:
model = BookingCheck
fields = ['start_time', 'end_time', 'presence', 'type_label', 'type_slug']
fields = ['presence', 'start_time', 'end_time', 'type_label', 'type_slug']
widgets = {
'start_time': widgets.TimeWidgetWithButton(
step=60, button_label=_('Fill with booking start time')
@ -611,13 +617,6 @@ 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
@ -633,13 +632,13 @@ 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['presence'] is None:
return
start_time = self.cleaned_data.get('start_time')
end_time = self.cleaned_data.get('end_time')
@ -663,8 +662,9 @@ class PartialBookingCheckForm(forms.ModelForm):
def save(self):
booking = self.instance.booking
if self.cleaned_data['presence'] is None:
self.instance.delete()
booking.refresh_computed_times(commit=True)
if self.instance.pk:
self.instance.delete()
booking.refresh_computed_times(commit=True)
return self.instance
super().save()

View File

@ -42,14 +42,13 @@
if (!this.checked)
return;
if (this.value == 'True') {
presence_check_type_select.show();
$(this).parents('.widget').siblings('.widget').show();
absence_check_type_select.hide();
} else if (this.value == 'False') {
absence_check_type_select.show();
$(this).parents('.widget').siblings('.widget').show();
presence_check_type_select.hide();
} else {
presence_check_type_select.hide();
absence_check_type_select.hide();
$(this).parents('.widget').siblings('.widget').hide();
}
}).change();

View File

@ -303,15 +303,9 @@ 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
@ -323,7 +317,6 @@ 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()
@ -372,6 +365,11 @@ def test_manager_partial_bookings_check(check_types, app, admin_user):
assert resp.pyquery('.time-widget-button')[0].text == 'Fill with booking start time'
assert resp.pyquery('.time-widget-button')[1].text == 'Fill with booking end time'
# submitting empty form works
assert resp.form['presence'].value == ''
resp = resp.form.submit().follow()
resp = resp.click('Booked period')
resp.form['start_time'] = '11:01'
resp.form['end_time'] = '11:00'
resp.form['presence'] = 'True'
@ -660,7 +658,8 @@ 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', True, None),
('', True, None),
('True', False, None),
] # no 'False' option
assert not Booking.objects.exists()