Skip to content

Commit

Permalink
Extended order search: Allow to search by quota
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Jan 12, 2024
1 parent 71f8a3a commit bae1512
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/pretix/control/forms/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
from pretix.base.models import (
Checkin, CheckinList, Device, Event, EventMetaProperty, EventMetaValue,
Gate, Invoice, InvoiceAddress, Item, Order, OrderPayment, OrderPosition,
OrderRefund, Organizer, Question, QuestionAnswer, SubEvent,
OrderRefund, Organizer, Question, QuestionAnswer, Quota, SubEvent,
SubEventMetaValue, Team, TeamAPIToken, TeamInvite, Voucher,
)
from pretix.base.signals import register_payment_providers
Expand Down Expand Up @@ -591,11 +591,10 @@ class EventOrderExpertFilterForm(EventOrderFilterForm):
widget=FilterNullBooleanSelect,
label=_('At least one ticket with check-in'),
)
checkin_attention = forms.NullBooleanField(
quota = SafeModelChoiceField(
queryset=Quota.objects.none(),
label=_('Affected quota'),
required=False,
widget=FilterNullBooleanSelect,
label=_('Requires special attention'),
help_text=_('Only matches orders with the attention checkbox set directly for the order, not based on the product.'),
)

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -680,6 +679,17 @@ def __init__(self, *args, **kwargs):
label=_('Ticket secret'),
required=False
)
self.fields['quota'].queryset = self.event.quotas.all()
self.fields['quota'].widget = Select2(
attrs={
'data-model-select2': 'generic',
'data-select2-url': reverse('control:event.items.quotas.select2', kwargs={
'event': self.event.slug,
'organizer': self.event.organizer.slug,
}),
}
)
self.fields['quota'].widget.choices = self.fields['quota'].choices
for q in self.event.questions.all():
self.fields['question_{}'.format(q.pk)] = forms.CharField(
label=q.question,
Expand Down Expand Up @@ -773,6 +783,12 @@ def filter_qs(self, qs):
qs = qs.filter(
all_positions__secret__icontains=fdata.get('ticket_secret')
).distinct()
if fdata.get('quota'):
quota = fdata['quota']
qs = qs.filter(
Q(all_positions__item__in=quota.items.all(), all_positions__variation__isnull=True) |
Q(all_positions__variation__in=quota.variations.all())
).distinct()
for q in self.event.questions.all():
if fdata.get(f'question_{q.pk}'):
answers = QuestionAnswer.objects.filter(
Expand Down

0 comments on commit bae1512

Please sign in to comment.