mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Quota form: Change item selection field per context (#3839)
* Change item checkbox select to multiselect widget * Make item selection widget dependent on count * Make item selection widget dependent on variable * Adjust widget choices * Fix widget choices * Fix item variation key errors * Simplify code * Fix classname * Improve argument name * Fix widget name
This commit is contained in:
@@ -295,6 +295,7 @@ class SubEventEditorMixin(MetaDataEditorMixin):
|
||||
]
|
||||
extra = 0
|
||||
|
||||
kwargs['searchable_selection'] = True
|
||||
formsetclass = inlineformset_factory(
|
||||
SubEvent, Quota,
|
||||
form=QuotaForm, formset=QuotaFormSet, min_num=1, validate_min=True,
|
||||
|
||||
@@ -684,6 +684,47 @@ def itemvar_select2(request, **kwargs):
|
||||
return JsonResponse(doc)
|
||||
|
||||
|
||||
@event_permission_required(None)
|
||||
def itemvars_select2(request, **kwargs):
|
||||
query = request.GET.get('query', '')
|
||||
try:
|
||||
page = int(request.GET.get('page', '1'))
|
||||
except ValueError:
|
||||
page = 1
|
||||
|
||||
pagesize = 20
|
||||
offset = (page - 1) * pagesize
|
||||
|
||||
choices = []
|
||||
|
||||
# We are very unlikely to need pagination
|
||||
itemqs = request.event.items.prefetch_related('variations').filter(
|
||||
Q(name__icontains=i18ncomp(query)) | Q(internal_name__icontains=query))
|
||||
total = itemqs.count()
|
||||
|
||||
for i in itemqs[offset:offset + pagesize]:
|
||||
variations = list(i.variations.all())
|
||||
if variations:
|
||||
for v in variations:
|
||||
choices.append(('%d-%d' % (i.pk, v.pk), '%s – %s' % (i, v.value), not v.active))
|
||||
else:
|
||||
choices.append((str(i.pk), str(i), not i.active))
|
||||
|
||||
doc = {
|
||||
'results': [
|
||||
{
|
||||
'id': k,
|
||||
'text': str(v),
|
||||
}
|
||||
for k, v, d in choices
|
||||
],
|
||||
'pagination': {
|
||||
"more": total >= (offset + pagesize)
|
||||
}
|
||||
}
|
||||
return JsonResponse(doc)
|
||||
|
||||
|
||||
@event_permission_required(None)
|
||||
def itemvarquota_select2(request, **kwargs):
|
||||
query = request.GET.get('query', '')
|
||||
|
||||
Reference in New Issue
Block a user