Skip to content

Commit

Permalink
Don't load a list of every user in the system when creating vouchers
Browse files Browse the repository at this point in the history
  • Loading branch information
mhagander committed Oct 8, 2024
1 parent 497cb4f commit 0e92a94
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion postgresqleu/confreg/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def clean(self):
class PrepaidCreateForm(forms.Form):
regtype = forms.ModelChoiceField(label="Registration type", queryset=RegistrationType.objects.filter(id=-1))
count = forms.IntegerField(label="Number of vouchers", min_value=1, max_value=100)
buyer = forms.ModelChoiceField(queryset=User.objects.all().order_by('username'), help_text="Pick the user who bought the batch. If he/she does not have an account, pick your own userid")
buyer = forms.ModelChoiceField(queryset=User.objects.filter(pk=-1).order_by('username'), help_text="Pick the user who bought the batch. If he/she does not have an account, pick your own userid")
invoice = forms.BooleanField(help_text="Automatically create invoice for these vouchers and send it to the person ordering them.", required=False)
invoiceaddress = forms.CharField(label="Invoice address", help_text="Complete address to put on invoice. Note that the name of the buyer is prepended to this!", required=False, widget=MonospaceTextarea)
confirm = forms.BooleanField(help_text="Confirm that the chosen registration type and count are correct (there is no undo past this point, the vouchers will be created!")
Expand All @@ -761,6 +761,9 @@ def __init__(self, conference, *args, **kwargs):
if 'invoice' in self.data and not self.data.get('invoiceaddress', ''):
del self.fields['confirm']

if 'data' in kwargs and 'buyer' in kwargs['data']:
self.fields['buyer'].queryset = User.objects.filter(pk__in=kwargs['data'].getlist('buyer'))

def clean(self):
cleaned_data = super(PrepaidCreateForm, self).clean()
if self.cleaned_data.get('invoice', False):
Expand Down

0 comments on commit 0e92a94

Please sign in to comment.