manager: warning on check_type edition if already used (#63847)
This commit is contained in:
parent
75044ae4f2
commit
0b38a91b2e
|
@ -22,6 +22,11 @@
|
|||
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{% if is_used %}
|
||||
<p>
|
||||
{% trans "This check type is set on some existing bookings, modify it with caution." %}
|
||||
</p>
|
||||
{% endif %}
|
||||
{{ form.as_p }}
|
||||
<div class="buttons">
|
||||
<button class="submit-button">{% trans "Save" %}</button>
|
||||
|
|
|
@ -796,6 +796,11 @@ class CheckTypeEditView(UpdateView):
|
|||
def get_queryset(self):
|
||||
return CheckType.objects.filter(group=self.group_pk)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['is_used'] = Booking.objects.filter(user_check_type=self.get_object()).exists()
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('chrono-manager-check-type-list')
|
||||
|
||||
|
|
|
@ -177,10 +177,14 @@ def test_edit_check_type(app, admin_user):
|
|||
check_type2 = CheckType.objects.create(label='Baz', group=group)
|
||||
group2 = CheckTypeGroup.objects.create(label='Foo bar')
|
||||
check_type3 = CheckType.objects.create(label='Foo bar reason', group=group2)
|
||||
agenda = Agenda.objects.create(label='Foo bar')
|
||||
event = Event.objects.create(agenda=agenda, start_datetime=now(), places=10)
|
||||
Booking.objects.create(event=event)
|
||||
|
||||
app = login(app)
|
||||
resp = app.get('/manage/check-types/')
|
||||
resp = resp.click(href='/manage/check-type/group/%s/%s/edit/' % (group.pk, check_type.pk))
|
||||
assert 'This check type is set on some existing bookings, modify it with caution.' not in resp
|
||||
resp.form['label'] = 'Foo bar reason'
|
||||
resp.form['slug'] = check_type2.slug
|
||||
assert 'kind' not in resp.context['form'].fields
|
||||
|
@ -197,6 +201,11 @@ def test_edit_check_type(app, admin_user):
|
|||
assert check_type.pricing is None
|
||||
assert check_type.pricing_rate is None
|
||||
|
||||
# check_type is used
|
||||
Booking.objects.update(user_check_type=check_type)
|
||||
resp = app.get('/manage/check-type/group/%s/%s/edit/' % (group.pk, check_type.pk))
|
||||
assert 'This check type is set on some existing bookings, modify it with caution.' in resp
|
||||
|
||||
app.get('/manage/check-type/group/%s/%s/edit/' % (group2.pk, check_type.pk), status=404)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue