Make voucher lookups case-insensitive

This commit is contained in:
Raphael Michel
2018-03-16 15:24:05 +01:00
parent b564fe8a0d
commit 5e3b4b126e
5 changed files with 12 additions and 10 deletions

View File

@@ -25,7 +25,7 @@ def _generate_random_code(prefix=None):
def generate_code(prefix=None):
while True:
code = _generate_random_code(prefix=prefix)
if not Voucher.objects.filter(code=code).exists():
if not Voucher.objects.filter(code__iexact=code).exists():
return code
@@ -278,11 +278,9 @@ class Voucher(LoggedModel):
if old_instance.quota:
quotas.add(old_instance.quota)
elif old_instance.variation:
quotas |= set(old_instance.variation.quotas.filter(
subevent=old_instance.subevent))
quotas |= set(old_instance.variation.quotas.filter(subevent=old_instance.subevent))
elif old_instance.item:
quotas |= set(old_instance.item.quotas.filter(
subevent=old_instance.subevent))
quotas |= set(old_instance.item.quotas.filter(subevent=old_instance.subevent))
return quotas
@staticmethod
@@ -313,7 +311,7 @@ class Voucher(LoggedModel):
@staticmethod
def clean_voucher_code(data, event, pk):
if 'code' in data and Voucher.objects.filter(Q(code=data['code']) & Q(event=event) & ~Q(pk=pk)).exists():
if 'code' in data and Voucher.objects.filter(Q(code__iexact=data['code']) & Q(event=event) & ~Q(pk=pk)).exists():
raise ValidationError(_('A voucher with this code already exists.'))
def save(self, *args, **kwargs):

View File

@@ -295,7 +295,7 @@ class CartManager:
if i.get('voucher'):
try:
voucher = self.event.vouchers.get(code=i.get('voucher').strip())
voucher = self.event.vouchers.get(code__iexact=i.get('voucher').strip())
except Voucher.DoesNotExist:
raise CartError(error_messages['voucher_invalid'])
else: