forked from CGM_Public/pretix_original
Improvements around the waiting list (#2219)
* Waiting list: Support for seated events, pre-fill customer email address * Allow people to remove themselves * Update src/pretix/base/settings.py Co-authored-by: Richard Schreiber <schreiber@rami.io> * Update src/pretix/control/views/waitinglist.py Co-authored-by: Richard Schreiber <schreiber@rami.io> * Update src/pretix/control/views/waitinglist.py Co-authored-by: Richard Schreiber <schreiber@rami.io> * Update src/pretix/control/views/waitinglist.py Co-authored-by: Richard Schreiber <schreiber@rami.io> * Update src/pretix/presale/views/waiting.py Co-authored-by: Richard Schreiber <schreiber@rami.io> * Resolve a review note * Review notes * Fix linter issues * Fix import Co-authored-by: Richard Schreiber <schreiber@rami.io>
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
from django import forms
|
||||
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from phonenumber_field.formfields import PhoneNumberField
|
||||
from phonenumbers.data import _COUNTRY_CODE_TO_REGION_CODE
|
||||
@@ -28,7 +29,8 @@ from pretix.base.forms.questions import (
|
||||
NamePartsFormField, WrappedPhoneNumberPrefixWidget, guess_country,
|
||||
)
|
||||
from pretix.base.i18n import get_babel_locale, language
|
||||
from pretix.base.models import WaitingListEntry
|
||||
from pretix.base.models import Quota, WaitingListEntry
|
||||
from pretix.presale.views.event import get_grouped_items
|
||||
|
||||
|
||||
class WaitingListForm(forms.ModelForm):
|
||||
@@ -40,8 +42,35 @@ class WaitingListForm(forms.ModelForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.event = kwargs.pop('event')
|
||||
self.channel = kwargs.pop('channel')
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
choices = [
|
||||
('', '')
|
||||
]
|
||||
items, display_add_to_cart = get_grouped_items(
|
||||
self.event, self.instance.subevent, require_seat=None
|
||||
)
|
||||
for i in items:
|
||||
if not i.allow_waitinglist:
|
||||
continue
|
||||
|
||||
if i.has_variations:
|
||||
for v in i.available_variations:
|
||||
if v.cached_availability[0] == Quota.AVAILABILITY_OK:
|
||||
continue
|
||||
choices.append((f'{i.pk}-{v.pk}', f'{i.name} – {v.value}'))
|
||||
|
||||
else:
|
||||
if i.cached_availability[0] == Quota.AVAILABILITY_OK:
|
||||
continue
|
||||
choices.append((f'{i.pk}', f'{i.name}'))
|
||||
|
||||
self.fields['itemvar'] = forms.ChoiceField(
|
||||
label=_('Product'),
|
||||
choices=choices,
|
||||
)
|
||||
|
||||
event = self.event
|
||||
|
||||
if event.settings.waiting_list_names_asked:
|
||||
@@ -73,3 +102,23 @@ class WaitingListForm(forms.ModelForm):
|
||||
)
|
||||
else:
|
||||
del self.fields['phone']
|
||||
|
||||
def clean(self):
|
||||
try:
|
||||
iv = self.data.get('itemvar', '')
|
||||
if '-' in iv:
|
||||
itemid, varid = iv.split('-')
|
||||
else:
|
||||
itemid, varid = iv, None
|
||||
|
||||
self.instance.item = self.instance.event.items.get(pk=itemid)
|
||||
if varid:
|
||||
self.instance.variation = self.instance.item.variations.get(pk=varid)
|
||||
else:
|
||||
self.instance.variation = None
|
||||
|
||||
except ObjectDoesNotExist:
|
||||
raise ValidationError(_("Invalid product selected."))
|
||||
|
||||
data = super().clean()
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user