Voucher import: Validate code not empty

This commit is contained in:
Raphael Michel
2024-04-26 11:20:36 +02:00
parent 42f3ca9661
commit 8aecf4f98f

View File

@@ -44,6 +44,8 @@ class CodeColumn(ImportColumn):
super().__init__(*args) super().__init__(*args)
def clean(self, value, previous_values): def clean(self, value, previous_values):
if not value:
raise ValidationError(_('A voucher cannot be created without a code.'))
if value: if value:
MinLengthValidator(5)(value) MinLengthValidator(5)(value)
if value and (value in self._cached or Voucher.objects.filter(event=self.event, code=value).exists()): if value and (value in self._cached or Voucher.objects.filter(event=self.event, code=value).exists()):