diff --git a/src/pretix/control/forms/filter.py b/src/pretix/control/forms/filter.py index 55e5a23a82..5805ede197 100644 --- a/src/pretix/control/forms/filter.py +++ b/src/pretix/control/forms/filter.py @@ -851,6 +851,32 @@ class UserFilterForm(FilterForm): class VoucherFilterForm(FilterForm): orders = { + 'code': 'code', + '-code': '-code', + 'redeemed': 'redeemed', + '-redeemed': '-redeemed', + 'valid_until': 'valid_until', + '-valid_until': '-valid_until', + 'tag': 'tag', + '-tag': '-tag', + 'item': ( + 'seat__sorting_rank', + 'item__category__position', + 'item__category', + 'item__position', + 'item__variation__position', + 'quota__name', + ), + 'subevent': 'subevent__date_from', + '-subevent': '-subevent__date_from', + '-item': ( + '-seat__sorting_rank', + '-item__category__position', + '-item__category', + '-item__position', + '-item__variation__position', + '-quota__name', + ) } status = forms.ChoiceField( label=_('Status'), @@ -987,7 +1013,15 @@ class VoucherFilterForm(FilterForm): qs = qs.filter(subevent_id=fdata.get('subevent').pk) if fdata.get('ordering'): - qs = qs.order_by(self.get_order_by()) + ob = self.orders[fdata.get('ordering')] + if isinstance(ob, dict): + ob = dict(ob) + o = ob.pop('_order') + qs = qs.annotate(**ob).order_by(o) + elif isinstance(ob, (list, tuple)): + qs = qs.order_by(*ob) + else: + qs = qs.order_by(ob) return qs diff --git a/src/pretix/control/templates/pretixcontrol/vouchers/index.html b/src/pretix/control/templates/pretixcontrol/vouchers/index.html index 08bf73a08a..381e15d21c 100644 --- a/src/pretix/control/templates/pretixcontrol/vouchers/index.html +++ b/src/pretix/control/templates/pretixcontrol/vouchers/index.html @@ -95,13 +95,37 @@ {% endif %} - {% trans "Voucher code" %} - {% trans "Redemptions" %} - {% trans "Expiry" %} - {% trans "Tag" %} - {% trans "Product" %} + + {% trans "Voucher code" %} + + + + + {% trans "Redemptions" %} + + + + + {% trans "Expiry" %} + + + + + {% trans "Tag" %} + + + + + {% trans "Product" %} + + + {% if request.event.has_subevents %} - {% trans "Date" context "subevent" %} + + {% trans "Date" context "subevent" %} + + + {% endif %}