mirror of
https://github.com/pretix/pretix.git
synced 2026-11-24 03:31:55 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
943f10ef18 | ||
|
|
3373d4bc67 |
No files matched your search
@@ -242,20 +242,26 @@
|
||||
<p> </p>
|
||||
<fieldset>
|
||||
<legend>{% trans "Check-in lists" %}</legend>
|
||||
{% if sampled_lists|default_if_none:"NONE" == "NONE" %}
|
||||
{% if block_list_change %}
|
||||
<div class="alert alert-info">
|
||||
{% blocktrans trimmed %}
|
||||
You selected a set of dates that currently have different check-in list setups. You can
|
||||
therefore not change their check-in lists in bulk.
|
||||
You selected a set of dates that currently have different check-in list setups and already
|
||||
contain checkins. You can therefore not change their check-in lists in bulk.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="bulk-edit-field-group">
|
||||
<label class="field-toggle">
|
||||
<input type="checkbox" name="_bulk" value="__checkinlists" {% if "__checkinlists" in bulk_selected %}checked{% endif %}>
|
||||
{% trans "change" context "form_bulk" %}
|
||||
</label>
|
||||
<div class="field-content">
|
||||
<div class="bulk-edit-field-group">
|
||||
<label class="field-toggle">
|
||||
<input type="checkbox" name="_bulk" value="__checkinlists" {% if "__checkinlists" in bulk_selected %}checked{% endif %}>
|
||||
{% trans "change" context "form_bulk" %}
|
||||
</label>
|
||||
<div class="field-content">
|
||||
{% if sampled_lists|default_if_none:"NONE" == "NONE" %}
|
||||
<div class="alert alert-warning">
|
||||
{% trans "You selected a set of dates that currently have different check-in list setups." %}
|
||||
{% trans "Using this option will <strong>delete all current check-in lists</strong> from <strong>all selected dates</strong>." %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="formset" data-formset data-formset-prefix="{{ cl_formset.prefix }}">
|
||||
{{ cl_formset.management_form }}
|
||||
{% bootstrap_formset_errors cl_formset %}
|
||||
|
||||
@@ -60,7 +60,7 @@ from django.views.generic import (
|
||||
)
|
||||
|
||||
from pretix.base.models import CartPosition, LogEntry, OrderPosition
|
||||
from pretix.base.models.checkin import CheckinList
|
||||
from pretix.base.models.checkin import Checkin, CheckinList
|
||||
from pretix.base.models.event import SubEvent, SubEventMetaValue
|
||||
from pretix.base.models.items import (
|
||||
Item, ItemVariation, Quota, SubEventItem, SubEventItemVariation,
|
||||
@@ -1320,9 +1320,13 @@ class SubEventBulkEdit(SubEventQueryMixin, EventPermissionRequiredMixin, FormVie
|
||||
extra = 0
|
||||
kwargs = {}
|
||||
|
||||
if self.sampled_lists is None:
|
||||
if self.block_list_change:
|
||||
return None
|
||||
kwargs['instance'] = self.get_queryset()[0]
|
||||
if self.sampled_lists is not None:
|
||||
try:
|
||||
kwargs['instance'] = self.get_queryset()[0]
|
||||
except IndexError:
|
||||
raise Http404("No matching dates")
|
||||
|
||||
formsetclass = inlineformset_factory(
|
||||
SubEvent, CheckinList,
|
||||
@@ -1335,7 +1339,7 @@ class SubEventBulkEdit(SubEventQueryMixin, EventPermissionRequiredMixin, FormVie
|
||||
)
|
||||
|
||||
def save_list_formset(self, log_entries):
|
||||
if self.sampled_lists is None or not self.list_formset.has_changed():
|
||||
if self.block_list_change or not self.list_formset.has_changed():
|
||||
return
|
||||
qidx = 0
|
||||
subevents = list(self.get_queryset().prefetch_related('checkinlist_set'))
|
||||
@@ -1343,6 +1347,21 @@ class SubEventBulkEdit(SubEventQueryMixin, EventPermissionRequiredMixin, FormVie
|
||||
to_save_gates = []
|
||||
to_delete_list_ids = []
|
||||
|
||||
if self.sampled_lists is None:
|
||||
if len(self.list_formset.forms) == 0:
|
||||
return
|
||||
else:
|
||||
for se in subevents:
|
||||
for q in se.checkinlist_set.all():
|
||||
to_delete_list_ids.append(q.pk)
|
||||
log_entries += [
|
||||
q.log_action(action='pretix.event.checkinlist.deleted', user=self.request.user, save=False),
|
||||
]
|
||||
|
||||
if to_delete_list_ids:
|
||||
CheckinList.objects.filter(id__in=to_delete_list_ids).delete()
|
||||
to_delete_list_ids = []
|
||||
|
||||
for f in self.list_formset.forms:
|
||||
if self.list_formset._should_delete_form(f) and f in self.list_formset.extra_forms:
|
||||
continue
|
||||
@@ -1494,6 +1513,7 @@ class SubEventBulkEdit(SubEventQueryMixin, EventPermissionRequiredMixin, FormVie
|
||||
ctx['filter_form'] = self.filter_form
|
||||
ctx['sampled_quotas'] = self.sampled_quotas
|
||||
ctx['sampled_lists'] = self.sampled_lists
|
||||
ctx['block_list_change'] = self.block_list_change
|
||||
ctx['formset'] = self.quota_formset
|
||||
ctx['cl_formset'] = self.list_formset
|
||||
ctx['itemvar_forms'] = self.itemvar_forms
|
||||
@@ -1540,6 +1560,14 @@ class SubEventBulkEdit(SubEventQueryMixin, EventPermissionRequiredMixin, FormVie
|
||||
return None
|
||||
return se.quotas.all()
|
||||
|
||||
@cached_property
|
||||
def block_list_change(self):
|
||||
if self.sampled_lists:
|
||||
return False # all the same, safe to change
|
||||
return Checkin.all.filter(
|
||||
list__subevent__in=self.get_queryset()
|
||||
).exists()
|
||||
|
||||
@cached_property
|
||||
def sampled_lists(self):
|
||||
all_lists = CheckinList.objects.filter(
|
||||
|
||||
@@ -1307,7 +1307,20 @@ class SubEventsTest(SoupTest):
|
||||
for se in [self.subevent1, self.subevent2]:
|
||||
assert se.checkinlist_set.count() == 1
|
||||
|
||||
def test_edit_bulk_lists_keep_mixed(self):
|
||||
def test_edit_bulk_lists_keep_mixed_if_checked_in(self):
|
||||
with scopes_disabled():
|
||||
self.subevent1.checkinlist_set.create(event=self.event1, name="C1")
|
||||
cl = self.subevent2.checkinlist_set.create(event=self.event1, name="C2")
|
||||
cl.checkins.create(
|
||||
successful=False,
|
||||
)
|
||||
doc = self.post_doc('/control/event/ccc/30c3/subevents/bulk_edit', {
|
||||
'__ALL': 'on',
|
||||
}, follow=True)
|
||||
fields = extract_form_fields(doc)
|
||||
assert 'checkinlist_set-TOTAL_FORMS' not in fields
|
||||
|
||||
def test_edit_bulk_lists_replace_mixed_if_unused(self):
|
||||
with scopes_disabled():
|
||||
self.subevent1.checkinlist_set.create(event=self.event1, name="C1")
|
||||
self.subevent2.checkinlist_set.create(event=self.event1, name="C2")
|
||||
@@ -1315,4 +1328,18 @@ class SubEventsTest(SoupTest):
|
||||
'__ALL': 'on',
|
||||
}, follow=True)
|
||||
fields = extract_form_fields(doc)
|
||||
assert 'checkinlist_set-TOTAL_FORMS' not in fields
|
||||
|
||||
fields.update({
|
||||
'_bulk': ['__checkinlists'],
|
||||
'checkinlist_set-TOTAL_FORMS': '1',
|
||||
'checkinlist_set-INITIAL_FORMS': '0',
|
||||
'checkinlist_set-MIN_NUM_FORMS': '0',
|
||||
'checkinlist_set-MAX_NUM_FORMS': '1000',
|
||||
'checkinlist_set-0-name': 'Default',
|
||||
'checkinlist_set-0-all_products': 'on',
|
||||
})
|
||||
doc = self.post_doc('/control/event/ccc/30c3/subevents/bulk_edit', fields, follow=True)
|
||||
assert doc.select(".alert-success")
|
||||
with scopes_disabled():
|
||||
assert self.subevent1.checkinlist_set.get().name == "Default"
|
||||
assert self.subevent2.checkinlist_set.get().name == "Default"
|
||||
Reference in new issue
Block a user