mirror of
https://github.com/pretix/pretix.git
synced 2026-08-17 11:56:27 +00:00
remove validations
This commit is contained in:
@@ -39,11 +39,18 @@ class WaitingListEntryEditForm(I18nModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.instance = kwargs.get('instance', None)
|
||||
initial = kwargs.get('initial', {})
|
||||
|
||||
choices = []
|
||||
if self.instance and self.instance.pk and 'itemvar' not in initial:
|
||||
if self.instance.variation is not None:
|
||||
initial['itemvar'] = f'{self.instance.item.pk}-{self.instance.variation.pk}'
|
||||
if self.instance.variation.active is False:
|
||||
choices.append((initial['itemvar'], str(self.instance.variation)))
|
||||
else:
|
||||
initial['itemvar'] = self.instance.item.pk
|
||||
if self.instance.item.active is False:
|
||||
choices.append((initial['itemvar'], str(self.instance)))
|
||||
|
||||
kwargs['initial'] = initial
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -78,29 +85,21 @@ class WaitingListEntryEditForm(I18nModelForm):
|
||||
if not self.event.settings.waiting_list_phones_asked:
|
||||
del self.fields['phone']
|
||||
|
||||
choices = []
|
||||
|
||||
items = self.event.items.prefetch_related('variations').prefetch_related('quotas')
|
||||
items = self.event.items.filter(active=True).prefetch_related('variations')
|
||||
|
||||
for item in items:
|
||||
# don't offer items in the selection if they don't allow waitinglists or aren't on sale at all
|
||||
if not item.allow_waitinglist | item.quotas.exists():
|
||||
# except if they are currently set in the waitinglist, this will be then caught on submit in the clean step
|
||||
if not self.instance.item.pk == item.pk:
|
||||
continue
|
||||
|
||||
if len(item.variations.all()) > 0:
|
||||
for v in item.variations.all():
|
||||
choices.append((
|
||||
'{}-{}'.format(item.pk, v.pk),
|
||||
'{} – {}'.format(item, v.value) if item.active else mark_safe(
|
||||
f'<strike class="text-muted">{escape(item)} – {escape(v.value)}</strike>')
|
||||
))
|
||||
active_variations = item.variations.filter(active=True)
|
||||
if len(active_variations) > 0:
|
||||
for variation in active_variations:
|
||||
choices.append(
|
||||
('{}-{}'.format(item.pk, variation.pk), str(variation))
|
||||
)
|
||||
else:
|
||||
choices.append(('{}'.format(item.pk), str(item) if item.active else mark_safe(
|
||||
f'<strike class="text-muted">{escape(item)}</strike>')))
|
||||
choices.append(('{}'.format(item.pk), str(item)))
|
||||
|
||||
self.fields['itemvar'].label = _("Product")
|
||||
self.fields['itemvar'].help_text = _("Only includes products which have the waiting list enabled.")
|
||||
self.fields['itemvar'].help_text = _("Only includes active products.")
|
||||
self.fields['itemvar'].required = True
|
||||
self.fields['itemvar'].widget = Select2ItemVarQuota(
|
||||
attrs={
|
||||
@@ -115,16 +114,17 @@ class WaitingListEntryEditForm(I18nModelForm):
|
||||
self.fields['itemvar'].choices = choices
|
||||
|
||||
def clean(self):
|
||||
if self.instance.voucher is not None:
|
||||
self.add_error(None, _('A voucher for this waiting list entry was sent out already.'))
|
||||
cleaned_data = super().clean()
|
||||
|
||||
itemvar = self.data.get('itemvar')
|
||||
if itemvar is None:
|
||||
self.add_error('itemvar', _('Item and Variation are required'))
|
||||
else:
|
||||
self.instance.item = Item.objects.get(pk=itemvar.split('-')[0])
|
||||
if self.instance.voucher is not None:
|
||||
raise ValidationError(_('A voucher for this waiting list entry was sent out already.'))
|
||||
|
||||
itemvar = cleaned_data.get('itemvar')
|
||||
|
||||
if itemvar:
|
||||
self.instance.item = self.event.items.get(pk=itemvar.split('-')[0])
|
||||
if '-' in itemvar:
|
||||
self.instance.variation = ItemVariation.objects.get(pk=itemvar.split('-')[1])
|
||||
self.instance.variation = self.instance.item.variations.get(pk=itemvar.split('-')[1])
|
||||
|
||||
if not self.instance.item.allow_waitinglist:
|
||||
self.add_error('itemvar', _('The selected product does not allow waiting list entries.'))
|
||||
@@ -132,9 +132,11 @@ class WaitingListEntryEditForm(I18nModelForm):
|
||||
self.add_error('itemvar', _('The selected product is not on sale because there is no quota configured for it.'))
|
||||
if self.instance.variation and not self.instance.variation.quotas.filter(subevent=self.data.get('subevent')).exists():
|
||||
self.add_error('itemvar', _('The selected product is not on sale because there is no quota configured for it.'))
|
||||
if ((self.instance.item and not self.instance.item.active) or
|
||||
(self.instance.variation and not self.instance.variation.active)):
|
||||
self.add_error('itemvar', _('The selected product is not active.'))
|
||||
|
||||
data = super().clean()
|
||||
return data
|
||||
return cleaned_data
|
||||
|
||||
class Meta:
|
||||
model = WaitingListEntry
|
||||
|
||||
Reference in New Issue
Block a user