mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Allow to add a prefix when generating voucher codes (#518)
This commit is contained in:
committed by
Raphael Michel
parent
8e3cc0df0c
commit
8fa490c938
@@ -278,10 +278,11 @@ class VoucherRNG(EventPermissionRequiredMixin, View):
|
||||
except ValueError: # NOQA
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
prefix = request.GET.get('prefix')
|
||||
while len(codes) < num:
|
||||
new_codes = set()
|
||||
for i in range(min(num - len(codes), 500)): # Work around SQLite's SQLITE_MAX_VARIABLE_NUMBER
|
||||
new_codes.add(_generate_random_code())
|
||||
new_codes.add(_generate_random_code(prefix=prefix))
|
||||
new_codes -= set([v['code'] for v in Voucher.objects.filter(code__in=new_codes).values('code')])
|
||||
codes |= new_codes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user