mirror of
https://github.com/pretix/pretix.git
synced 2026-05-07 15:34:02 +00:00
Waiting list: group product choices by category (#6006)
* Group waiting list product choices by category Use optgroups to group products by category in the waiting list selection dropdown. Products are normally separated in the UI by category grouping, but this context is lost in the waiting list form. When multiple products share the same name, this can make it difficult for customers to distinguish between them. * Add tests for waiting list initial selection with optgroups Verify that the initial product selection (via `?item=` and `?var=` query parameters) works correctly when choices are grouped by category into `<optgroup>`s. Covers both plain items and items with variations.
This commit is contained in:
@@ -66,22 +66,27 @@ class WaitingView(EventViewMixin, FormView):
|
||||
if customer else None
|
||||
),
|
||||
)
|
||||
choices = []
|
||||
groups = {}
|
||||
for i in items:
|
||||
if not i.allow_waitinglist:
|
||||
continue
|
||||
|
||||
category_name = str(i.category.name) if i.category else ''
|
||||
group = groups.setdefault(category_name, [])
|
||||
|
||||
if i.has_variations:
|
||||
for v in i.available_variations:
|
||||
if v.cached_availability[0] == Quota.AVAILABILITY_OK:
|
||||
continue
|
||||
choices.append((f'{i.pk}-{v.pk}', f'{i.name} – {v.value}'))
|
||||
group.append((f'{i.pk}-{v.pk}', f'{i.name} – {v.value}'))
|
||||
|
||||
else:
|
||||
if i.cached_availability[0] == Quota.AVAILABILITY_OK:
|
||||
continue
|
||||
choices.append((f'{i.pk}', f'{i.name}'))
|
||||
return choices
|
||||
group.append((f'{i.pk}', f'{i.name}'))
|
||||
|
||||
# Remove categories where all items were available (no waiting list choices)
|
||||
return [(cat, choices) for cat, choices in groups.items() if choices]
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
|
||||
Reference in New Issue
Block a user