mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +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
@@ -10,8 +10,11 @@
|
||||
{% bootstrap_form_errors form %}
|
||||
<fieldset>
|
||||
<legend>{% trans "Voucher codes" %}</legend>
|
||||
<div class="form-group">
|
||||
<div class="form-group form-inline">
|
||||
<div class="col-md-7 col-sm-12 col-md-offset-3">
|
||||
<input type="text" class="form-control input-xs"
|
||||
id="voucher-bulk-codes-prefix"
|
||||
placeholder="{% trans "Prefix (optional)" %}">
|
||||
<div class="input-group">
|
||||
<input type="number" class="form-control input-xs"
|
||||
id="voucher-bulk-codes-num"
|
||||
|
||||
@@ -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