mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Add Subevent-Filter for Voucher-Tags (#1407)
* Add Subevent-Filter for Voucher-Tags * Filter Subevent Voucher-Tags with proper Filter * Apply filter before annotating totals and usage
This commit is contained in:
committed by
Raphael Michel
parent
a884a25d2b
commit
cf14dcf889
@@ -19,7 +19,7 @@ from django.views.generic import (
|
||||
|
||||
from pretix.base.models import CartPosition, LogEntry, OrderPosition, Voucher
|
||||
from pretix.base.models.vouchers import _generate_random_code
|
||||
from pretix.control.forms.filter import VoucherFilterForm
|
||||
from pretix.control.forms.filter import VoucherFilterForm, VoucherTagFilterForm
|
||||
from pretix.control.forms.vouchers import VoucherBulkForm, VoucherForm
|
||||
from pretix.control.permissions import EventPermissionRequiredMixin
|
||||
from pretix.control.signals import voucher_form_class
|
||||
@@ -94,16 +94,27 @@ class VoucherTags(EventPermissionRequiredMixin, TemplateView):
|
||||
template_name = 'pretixcontrol/vouchers/tags.html'
|
||||
permission = 'can_view_vouchers'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super().get_context_data(**kwargs)
|
||||
|
||||
tags = self.request.event.vouchers.order_by('tag').filter(
|
||||
def get_queryset(self):
|
||||
qs = self.request.event.vouchers.order_by('tag').filter(
|
||||
tag__isnull=False,
|
||||
waitinglistentries__isnull=True
|
||||
).values('tag').annotate(
|
||||
)
|
||||
|
||||
if self.filter_form.is_valid():
|
||||
qs = self.filter_form.filter_qs(qs)
|
||||
|
||||
qs = qs.values('tag').annotate(
|
||||
total=Sum('max_usages'),
|
||||
redeemed=Sum('redeemed')
|
||||
)
|
||||
|
||||
return qs.distinct()
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super().get_context_data(**kwargs)
|
||||
|
||||
tags = self.get_queryset()
|
||||
|
||||
for t in tags:
|
||||
if t['total'] == 0:
|
||||
t['percentage'] = 0
|
||||
@@ -111,8 +122,13 @@ class VoucherTags(EventPermissionRequiredMixin, TemplateView):
|
||||
t['percentage'] = int((t['redeemed'] / t['total']) * 100)
|
||||
|
||||
ctx['tags'] = tags
|
||||
ctx['filter_form'] = self.filter_form
|
||||
return ctx
|
||||
|
||||
@cached_property
|
||||
def filter_form(self):
|
||||
return VoucherTagFilterForm(data=self.request.GET, event=self.request.event)
|
||||
|
||||
|
||||
class VoucherDelete(EventPermissionRequiredMixin, DeleteView):
|
||||
model = Voucher
|
||||
|
||||
Reference in New Issue
Block a user