def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['voucher'] = self.voucher context['max_times'] = self.voucher.max_usages - self.voucher.redeemed # Fetch all items items, display_add_to_cart = get_grouped_items(self.request.event, self.subevent, voucher=self.voucher, channel=self.request.sales_channel) # Calculate how many options the user still has. If there is only one option, we can # check the box right away ;) context['options'] = sum([(len(item.available_variations) if item.has_variations else 1) for item in items]) # Regroup those by category context['items_by_category'] = item_group_by_category(items) context['subevent'] = self.subevent context['new_tab'] = ( 'require_cookie' in self.request.GET and settings.SESSION_COOKIE_NAME not in self.request.COOKIES # Cookies are not supported! Lets just make the form open in a new tab ) return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['voucher'] = self.voucher context['max_times'] = self.voucher.max_usages - self.voucher.redeemed # Fetch all items items, display_add_to_cart = get_grouped_items(self.request.event, self.subevent, voucher=self.voucher) # Calculate how many options the user still has. If there is only one option, we can # check the box right away ;) context['options'] = sum([ (len(item.available_variations) if item.has_variations else 1) for item in items ]) # Regroup those by category context['items_by_category'] = item_group_by_category(items) context['subevent'] = self.subevent context['new_tab'] = ( 'require_cookie' in self.request.GET and settings.SESSION_COOKIE_NAME not in self.request.COOKIES # Cookies are not supported! Lets just make the form open in a new tab ) return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['voucher'] = self.voucher context['max_times'] = self.voucher.max_usages - self.voucher.redeemed # Fetch all items items, display_add_to_cart = get_grouped_items( self.request.event, self.subevent, voucher=self.voucher, channel=self.request.sales_channel.identifier) # Calculate how many options the user still has. If there is only one option, we can # check the box right away ;) context['options'] = sum([ (len(item.available_variations) if item.has_variations else 1) for item in items ]) context['allfree'] = all( item.display_price.gross == Decimal('0.00') for item in items if not item.has_variations) and all( all(var.display_price.gross == Decimal('0.00') for var in item.available_variations) for item in items if item.has_variations) # Regroup those by category context['items_by_category'] = item_group_by_category(items) context['subevent'] = self.subevent context[ 'seating_available'] = self.request.event.settings.seating_choice and self.voucher.seating_available( self.subevent) context['new_tab'] = ( 'require_cookie' in self.request.GET and settings.SESSION_COOKIE_NAME not in self.request.COOKIES # Cookies are not supported! Lets just make the form open in a new tab ) if self.request.event.settings.redirect_to_checkout_directly: context['cart_redirect'] = eventreverse( self.request.event, 'presale:event.checkout.start', kwargs={'cart_namespace': kwargs.get('cart_namespace') or ''}) else: context['cart_redirect'] = eventreverse( self.request.event, 'presale:event.index', kwargs={'cart_namespace': kwargs.get('cart_namespace') or ''}) if context['cart_redirect'].startswith('https:'): context['cart_redirect'] = '/' + context['cart_redirect'].split( '/', 3)[3] return context
def _get_items(self): items, display_add_to_cart = get_grouped_items( self.request.event, subevent=self.subevent, voucher=self.voucher, channel='web' ) grps = [] for cat, g in item_group_by_category(items): grps.append({ 'id': cat.pk if cat else None, 'name': str(cat.name) if cat else None, 'description': str(rich_text(cat.description, safelinks=False)) if cat and cat.description else None, 'items': [ { 'id': item.pk, 'name': str(item.name), 'picture': get_picture(self.request.event, item.picture) if item.picture else None, 'description': str(rich_text(item.description, safelinks=False)) if item.description else None, 'has_variations': item.has_variations, 'require_voucher': item.require_voucher, 'order_min': item.min_per_order, 'order_max': item.order_max if not item.has_variations else None, 'price': price_dict(item.display_price) if not item.has_variations else None, 'min_price': item.min_price if item.has_variations else None, 'max_price': item.max_price if item.has_variations else None, 'free_price': item.free_price, 'avail': [ item.cached_availability[0], item.cached_availability[1] if self.request.event.settings.show_quota_left else None ] if not item.has_variations else None, 'original_price': item.original_price, 'variations': [ { 'id': var.id, 'value': str(var.value), 'order_max': var.order_max, 'description': str(rich_text(var.description, safelinks=False)) if var.description else None, 'price': price_dict(var.display_price), 'avail': [ var.cached_availability[0], var.cached_availability[1] if self.request.event.settings.show_quota_left else None ], } for var in item.available_variations ] } for item in g ] }) return grps, display_add_to_cart, len(items)
def _get_items(self): items, display_add_to_cart = get_grouped_items( self.request.event, subevent=self.subevent, voucher=self.voucher, channel='web' ) grps = [] for cat, g in item_group_by_category(items): grps.append({ 'id': cat.pk if cat else None, 'name': str(cat.name) if cat else None, 'description': str(rich_text(cat.description, safelinks=False)) if cat and cat.description else None, 'items': [ { 'id': item.pk, 'name': str(item.name), 'picture': get_picture(self.request.event, item.picture) if item.picture else None, 'description': str(rich_text(item.description, safelinks=False)) if item.description else None, 'has_variations': item.has_variations, 'require_voucher': item.require_voucher, 'order_min': item.min_per_order, 'order_max': item.order_max if not item.has_variations else None, 'price': price_dict(item.display_price) if not item.has_variations else None, 'min_price': item.min_price if item.has_variations else None, 'max_price': item.max_price if item.has_variations else None, 'free_price': item.free_price, 'avail': [ item.cached_availability[0], item.cached_availability[1] if self.request.event.settings.show_quota_left else None ] if not item.has_variations else None, 'original_price': item.original_price, 'variations': [ { 'id': var.id, 'value': str(var.value), 'order_max': var.order_max, 'description': str(rich_text(var.description, safelinks=False)) if var.description else None, 'price': price_dict(var.display_price), 'avail': [ var.cached_availability[0], var.cached_availability[1] if self.request.event.settings.show_quota_left else None ], } for var in item.available_variations ] } for item in g ] }) return grps, display_add_to_cart, len(items)
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['voucher'] = self.voucher context['max_times'] = self.voucher.max_usages - self.voucher.redeemed # Fetch all items items, display_add_to_cart = get_grouped_items(self.request.event, self.subevent, voucher=self.voucher) # Calculate how many options the user still has. If there is only one option, we can # check the box right away ;) context['options'] = sum([(len(item.available_variations) if item.has_variations else 1) for item in items]) # Regroup those by category context['items_by_category'] = item_group_by_category(items) context['subevent'] = self.subevent return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['voucher'] = self.voucher context['max_times'] = self.voucher.max_usages - self.voucher.redeemed # Fetch all items items, display_add_to_cart = get_grouped_items(self.request.event, self.subevent, voucher=self.voucher, channel=self.request.sales_channel) # Calculate how many options the user still has. If there is only one option, we can # check the box right away ;) context['options'] = sum([(len(item.available_variations) if item.has_variations else 1) for item in items]) # Regroup those by category context['items_by_category'] = item_group_by_category(items) context['subevent'] = self.subevent context['new_tab'] = ( 'require_cookie' in self.request.GET and settings.SESSION_COOKIE_NAME not in self.request.COOKIES # Cookies are not supported! Lets just make the form open in a new tab ) if self.request.event.settings.redirect_to_checkout_directly: context['cart_redirect'] = eventreverse(self.request.event, 'presale:event.checkout.start', kwargs={'cart_namespace': kwargs.get('cart_namespace') or ''}) else: context['cart_redirect'] = eventreverse(self.request.event, 'presale:event.index', kwargs={'cart_namespace': kwargs.get('cart_namespace') or ''}) if context['cart_redirect'].startswith('https:'): context['cart_redirect'] = '/' + context['cart_redirect'].split('/', 3)[3] return context
def _get_items(self): qs = self.request.event.items if 'items' in self.request.GET: qs = qs.filter(pk__in=self.request.GET.get('items').split(",")) if 'categories' in self.request.GET: qs = qs.filter( category__pk__in=self.request.GET.get('categories').split(",")) items, display_add_to_cart = get_grouped_items( self.request.event, subevent=self.subevent, voucher=self.voucher, channel=self.request.sales_channel.identifier, base_qs=qs) grps = [] for cat, g in item_group_by_category(items): grps.append({ 'id': cat.pk if cat else None, 'name': str(cat.name) if cat else None, 'description': str(rich_text(cat.description, safelinks=False)) if cat and cat.description else None, 'items': [{ 'id': item.pk, 'name': str(item.name), 'picture': get_picture(self.request.event, item.picture) if item.picture else None, 'description': str(rich_text(item.description, safelinks=False)) if item.description else None, 'has_variations': item.has_variations, 'require_voucher': item.require_voucher, 'order_min': item.min_per_order, 'order_max': item.order_max if not item.has_variations else None, 'price': price_dict(item, item.display_price) if not item.has_variations else None, 'min_price': item.min_price if item.has_variations else None, 'max_price': item.max_price if item.has_variations else None, 'allow_waitinglist': item.allow_waitinglist, 'free_price': item.free_price, 'avail': [ item.cached_availability[0], item.cached_availability[1] if item.do_show_quota_left else None ] if not item.has_variations else None, 'original_price': ((item.original_price.net if self.request.event.settings. display_net_prices else item.original_price.gross) if item.original_price else None), 'variations': [{ 'id': var.id, 'value': str(var.value), 'order_max': var.order_max, 'description': str(rich_text(var.description, safelinks=False)) if var.description else None, 'price': price_dict(item, var.display_price), 'original_price': ((var.original_price.net if self.request.event.settings .display_net_prices else var.original_price.gross) if var.original_price else None) or ((item.original_price.net if self.request.event.settings.display_net_prices else item.original_price.gross) if item.original_price else None), 'avail': [ var.cached_availability[0], var.cached_availability[1] if item.do_show_quota_left else None ], } for var in item.available_variations] } for item in g] }) return grps, display_add_to_cart, len(items)
def forms(self): """ A list of forms with one form for each cart position that can have add-ons. All forms have a custom prefix, so that they can all be submitted at once. """ formset = [] quota_cache = {} item_cache = {} for cartpos in get_cart( self.request).filter(addon_to__isnull=True).prefetch_related( 'item__addons', 'item__addons__addon_category', 'addons', 'addons__variation', ).order_by('pk'): formsetentry = { 'cartpos': cartpos, 'item': cartpos.item, 'variation': cartpos.variation, 'categories': [] } formset.append(formsetentry) current_addon_products = defaultdict(list) for a in cartpos.addons.all(): if not a.is_bundled: current_addon_products[a.item_id, a.variation_id].append(a) for iao in cartpos.item.addons.all(): ckey = '{}-{}'.format( cartpos.subevent.pk if cartpos.subevent else 0, iao.addon_category.pk) if ckey not in item_cache: # Get all items to possibly show items, _btn = get_grouped_items( self.request.event, subevent=cartpos.subevent, voucher=None, channel=self.request.sales_channel.identifier, base_qs=iao.addon_category.items, allow_addons=True, quota_cache=quota_cache) item_cache[ckey] = items else: items = item_cache[ckey] for i in items: i.allow_waitinglist = False if i.has_variations: for v in i.available_variations: v.initial = len(current_addon_products[i.pk, v.pk]) if v.initial and i.free_price: a = current_addon_products[i.pk, v.pk][0] v.initial_price = TaxedPrice( net=a.price - a.tax_value, gross=a.price, tax=a.tax_value, name=a.item.tax_rule.name, rate=a.tax_rate, ) else: v.initial_price = v.display_price i.expand = any(v.initial for v in i.available_variations) else: i.initial = len(current_addon_products[i.pk, None]) if i.initial and i.free_price: a = current_addon_products[i.pk, None][0] i.initial_price = TaxedPrice( net=a.price - a.tax_value, gross=a.price, tax=a.tax_value, name=a.item.tax_rule.name, rate=a.tax_rate, ) else: i.initial_price = i.display_price if items: formsetentry['categories'].append({ 'category': iao.addon_category, 'price_included': iao.price_included, 'multi_allowed': iao.multi_allowed, 'min_count': iao.min_count, 'max_count': iao.max_count, 'iao': iao, 'items': items }) return formset
def __init__(self, *args, **kwargs): self.event = kwargs.pop('event') self.channel = kwargs.pop('channel') customer = kwargs.pop('customer') super().__init__(*args, **kwargs) choices = [('', '')] items, display_add_to_cart = get_grouped_items( self.event, self.instance.subevent, require_seat=None, memberships=(customer.usable_memberships( for_event=self.instance.subevent or self.event, testmode=self.event.testmode) if customer else 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: self.fields['name_parts'] = NamePartsFormField( max_length=255, required=event.settings.waiting_list_names_required, scheme=event.settings.name_scheme, titles=event.settings.name_scheme_titles, label=_('Name'), ) else: del self.fields['name_parts'] if event.settings.waiting_list_phones_asked: if not self.initial.get('phone'): phone_prefix = guess_phone_prefix(event) if phone_prefix: self.initial['phone'] = "+{}.".format(phone_prefix) self.fields['phone'] = PhoneNumberField( label=_("Phone number"), required=event.settings.waiting_list_phones_required, help_text=event.settings.waiting_list_phones_explanation_text, widget=WrappedPhoneNumberPrefixWidget()) else: del self.fields['phone']
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: self.fields['name_parts'] = NamePartsFormField( max_length=255, required=event.settings.waiting_list_names_required, scheme=event.settings.name_scheme, titles=event.settings.name_scheme_titles, label=_('Name'), ) else: del self.fields['name_parts'] if event.settings.waiting_list_phones_asked: with language(get_babel_locale()): default_country = guess_country(self.event) for prefix, values in _COUNTRY_CODE_TO_REGION_CODE.items(): if str(default_country ) in values and not self.initial.get('phone'): # We now exploit an implementation detail in PhoneNumberPrefixWidget to allow us to pass just # a country code but no number as an initial value. It's a bit hacky, but should be stable for # the future. self.initial['phone'] = "+{}.".format(prefix) self.fields['phone'] = PhoneNumberField( label=_("Phone number"), required=event.settings.waiting_list_phones_required, help_text=event.settings. waiting_list_phones_explanation_text, widget=WrappedPhoneNumberPrefixWidget()) else: del self.fields['phone']