mirror of
https://github.com/pretix/pretix.git
synced 2026-08-27 13:24:41 +00:00
Add a minimal length for voucher codes
This commit is contained in:
@@ -2,6 +2,7 @@ from decimal import Decimal
|
|||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.core.validators import MinLengthValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.crypto import get_random_string
|
from django.utils.crypto import get_random_string
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
@@ -92,6 +93,7 @@ class Voucher(LoggedModel):
|
|||||||
verbose_name=_("Voucher code"),
|
verbose_name=_("Voucher code"),
|
||||||
max_length=255, default=generate_code,
|
max_length=255, default=generate_code,
|
||||||
db_index=True,
|
db_index=True,
|
||||||
|
validators=[MinLengthValidator(5)]
|
||||||
)
|
)
|
||||||
max_usages = models.PositiveIntegerField(
|
max_usages = models.PositiveIntegerField(
|
||||||
verbose_name=_("Maximum usages"),
|
verbose_name=_("Maximum usages"),
|
||||||
|
|||||||
@@ -205,6 +205,12 @@ class VoucherFormTest(SoupTest):
|
|||||||
v = Voucher.objects.latest('pk')
|
v = Voucher.objects.latest('pk')
|
||||||
assert v.block_quota
|
assert v.block_quota
|
||||||
|
|
||||||
|
def test_create_short_code(self):
|
||||||
|
self._create_voucher({
|
||||||
|
'itemvar': '%d-%d' % (self.shirt.pk, self.shirt_red.pk),
|
||||||
|
'code': 'ABC'
|
||||||
|
}, expected_failure=True)
|
||||||
|
|
||||||
def test_create_blocking_variation_voucher_quota_full(self):
|
def test_create_blocking_variation_voucher_quota_full(self):
|
||||||
self.quota_shirts.size = 0
|
self.quota_shirts.size = 0
|
||||||
self.quota_shirts.save()
|
self.quota_shirts.save()
|
||||||
|
|||||||
Reference in New Issue
Block a user