Improve handling of protected subevents during deletion

This commit is contained in:
Raphael Michel
2022-06-03 14:04:15 +02:00
parent 772a4ce494
commit d98cb6402c
2 changed files with 13 additions and 4 deletions

View File

@@ -16,6 +16,12 @@
</li>
{% endfor %}
</ul>
<div class="alert-info alert">
{% blocktrans trimmed %}
It is possible that some of the above dates can't be deleted if a plugin has data attached to them.
In that case, they will be disabled instead.
{% endblocktrans %}
</div>
{% endif %}
{% if forbidden %}
<p>{% blocktrans trimmed %}The following dates can't be deleted as they already have orders, but
@@ -30,7 +36,8 @@
</ul>
{% endif %}
<div class="form-group submit-group">
<a href="{% url "control:event.subevents" organizer=request.event.organizer.slug event=request.event.slug %}" class="btn btn-default btn-cancel">
<a href="{% url "control:event.subevents" organizer=request.event.organizer.slug event=request.event.slug %}"
class="btn btn-default btn-cancel">
{% trans "Cancel" %}
</a>
<button type="submit" class="btn btn-danger btn-save" value="delete_confirm" name="action">

View File

@@ -41,7 +41,7 @@ from django.contrib import messages
from django.core.exceptions import ValidationError
from django.core.files import File
from django.db import connections, transaction
from django.db.models import Count, F, Prefetch
from django.db.models import Count, F, Prefetch, ProtectedError
from django.db.models.functions import Coalesce, TruncDate, TruncTime
from django.forms import inlineformset_factory
from django.http import Http404, HttpResponse, HttpResponseRedirect
@@ -639,12 +639,14 @@ class SubEventBulkAction(SubEventQueryMixin, EventPermissionRequiredMixin, View)
})
elif request.POST.get('action') == 'delete_confirm':
for obj in self.get_queryset():
if obj.allow_delete():
try:
if not obj.allow_delete():
raise ProtectedError('only deactivate', [obj])
CartPosition.objects.filter(addon_to__subevent=obj).delete()
obj.cartposition_set.all().delete()
obj.log_action('pretix.subevent.deleted', user=self.request.user)
obj.delete()
else:
except ProtectedError:
obj.log_action(
'pretix.subevent.changed', user=self.request.user, data={
'active': False