Don't load a list of every user in the system when creating vouchers
authorMagnus Hagander <magnus@hagander.net>
Tue, 8 Oct 2024 12:07:13 +0000 (14:07 +0200)
committerMagnus Hagander <magnus@hagander.net>
Tue, 8 Oct 2024 12:07:13 +0000 (14:07 +0200)
postgresqleu/confreg/forms.py

index e5b264e2a2f01351f9554de5cd3aebaabc28d0c7..79bde8aa7a277f8dca595670f78c1828d77af091 100644 (file)
@@ -739,7 +739,7 @@ class SessionSlidesFileForm(forms.Form):
 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!")
@@ -761,6 +761,9 @@ class PrepaidCreateForm(forms.Form):
         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):