Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
    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
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
    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
Пример #7
0
    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
Пример #8
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        context['voucher'] = self.voucher

        # Fetch all items
        items = self.request.event.items.all().filter(
            Q(active=True)
            & Q(Q(available_from__isnull=True) | Q(available_from__lte=now()))
            & Q(Q(available_until__isnull=True) | Q(available_until__gte=now()))
        )

        vouchq = Q(hide_without_voucher=False)

        if self.voucher.item_id:
            vouchq |= Q(pk=self.voucher.item_id)
            items = items.filter(pk=self.voucher.item_id)
        elif self.voucher.quota_id:
            items = items.filter(quotas__in=[self.voucher.quota_id])

        items = items.filter(vouchq).select_related(
            'category',  # for re-grouping
        ).prefetch_related(
            'quotas', 'variations__quotas', 'quotas__event'  # for .availability()
        ).annotate(quotac=Count('quotas')).filter(
            quotac__gt=0
        ).distinct().order_by('category__position', 'category_id', 'position', 'name')

        for item in items:
            item.available_variations = list(item.variations.filter(active=True, quotas__isnull=False).distinct())
            if self.voucher.item_id and self.voucher.variation_id:
                item.available_variations = [v for v in item.available_variations if v.pk == self.voucher.variation_id]

            item.has_variations = item.variations.exists()
            if not item.has_variations:
                if self.voucher.allow_ignore_quota or self.voucher.block_quota:
                    item.cached_availability = (Quota.AVAILABILITY_OK, 1)
                else:
                    item.cached_availability = item.check_quotas()
                if self.voucher.price is not None:
                    item.price = self.voucher.price
                else:
                    item.price = item.default_price
            else:
                for var in item.available_variations:
                    if self.voucher.allow_ignore_quota or self.voucher.block_quota:
                        var.cached_availability = (Quota.AVAILABILITY_OK, 1)
                    else:
                        var.cached_availability = list(var.check_quotas())
                    if self.voucher.price is not None:
                        var.price = self.voucher.price
                    else:
                        var.price = var.default_price if var.default_price is not None else item.default_price

                if len(item.available_variations) > 0:
                    item.min_price = min([v.price for v in item.available_variations])
                    item.max_price = max([v.price for v in item.available_variations])

        items = [item for item in items if len(item.available_variations) > 0 or not item.has_variations]
        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)

        return context
Пример #9
0
    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)
Пример #10
0
    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 = self.request.event.items.all().filter(
            Q(active=True)
            & Q(Q(available_from__isnull=True) | Q(available_from__lte=now()))
            & Q(Q(available_until__isnull=True) | Q(available_until__gte=now()))
            & ~Q(category__is_addon=True)
        )

        vouchq = Q(hide_without_voucher=False)

        if self.voucher.item_id:
            vouchq |= Q(pk=self.voucher.item_id)
            items = items.filter(pk=self.voucher.item_id)
        elif self.voucher.quota_id:
            items = items.filter(quotas__in=[self.voucher.quota_id])

        items = items.filter(vouchq).select_related(
            'category', 'tax_rule',  # for re-grouping
        ).prefetch_related(
            Prefetch('quotas',
                     to_attr='_subevent_quotas',
                     queryset=self.request.event.quotas.filter(subevent=self.subevent)),
            Prefetch('variations', to_attr='available_variations',
                     queryset=ItemVariation.objects.filter(active=True, quotas__isnull=False).prefetch_related(
                         Prefetch('quotas',
                                  to_attr='_subevent_quotas',
                                  queryset=self.request.event.quotas.filter(subevent=self.subevent))
                     ).distinct()),
        ).annotate(
            quotac=Count('quotas'),
            has_variations=Count('variations')
        ).filter(
            quotac__gt=0
        ).distinct().order_by('category__position', 'category_id', 'position', 'name')
        quota_cache = {}

        if self.subevent:
            item_price_override = self.subevent.item_price_overrides
            var_price_override = self.subevent.var_price_overrides
        else:
            item_price_override = {}
            var_price_override = {}

        for item in items:
            if self.voucher.item_id and self.voucher.variation_id:
                item.available_variations = [v for v in item.available_variations if v.pk == self.voucher.variation_id]

            item.order_max = item.max_per_order or int(self.request.event.settings.max_items_per_order)

            if not item.has_variations:
                item._remove = not bool(item._subevent_quotas)
                if self.voucher.allow_ignore_quota or self.voucher.block_quota:
                    item.cached_availability = (Quota.AVAILABILITY_OK, 1)
                else:
                    item.cached_availability = item.check_quotas(subevent=self.subevent, _cache=quota_cache)

                price = item_price_override.get(item.pk, item.default_price)
                price = self.voucher.calculate_price(price)
                item.display_price = item.tax(price)
            else:
                item._remove = False
                for var in item.available_variations:
                    if self.voucher.allow_ignore_quota or self.voucher.block_quota:
                        var.cached_availability = (Quota.AVAILABILITY_OK, 1)
                    else:
                        var.cached_availability = list(var.check_quotas(subevent=self.subevent, _cache=quota_cache))

                    price = var_price_override.get(var.pk, var.price)
                    price = self.voucher.calculate_price(price)
                    var.display_price = item.tax(price)

                item.available_variations = [
                    v for v in item.available_variations if v._subevent_quotas
                ]
                if self.voucher.variation_id:
                    item.available_variations = [v for v in item.available_variations
                                                 if v.pk == self.voucher.variation_id]
                if len(item.available_variations) > 0:
                    item.min_price = min([v.display_price.net if self.request.event.settings.display_net_prices else
                                          v.display_price.gross for v in item.available_variations])
                    item.max_price = max([v.display_price.net if self.request.event.settings.display_net_prices else
                                          v.display_price.gross for v in item.available_variations])

        items = [item for item in items
                 if (len(item.available_variations) > 0 or not item.has_variations) and not item._remove]
        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
Пример #11
0
    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 = self.request.event.items.all().filter(
            Q(active=True)
            & Q(Q(available_from__isnull=True) | Q(available_from__lte=now()))
            &
            Q(Q(available_until__isnull=True) | Q(available_until__gte=now())))

        vouchq = Q(hide_without_voucher=False)

        if self.voucher.item_id:
            vouchq |= Q(pk=self.voucher.item_id)
            items = items.filter(pk=self.voucher.item_id)
        elif self.voucher.quota_id:
            items = items.filter(quotas__in=[self.voucher.quota_id])

        items = items.filter(vouchq).select_related(
            'category',  # for re-grouping
        ).prefetch_related(
            'quotas',
            'variations__quotas',
            'quotas__event'  # for .availability()
        ).annotate(quotac=Count('quotas')).filter(
            quotac__gt=0).distinct().order_by('category__position',
                                              'category_id', 'position',
                                              'name')

        for item in items:
            item.available_variations = list(
                item.variations.filter(active=True,
                                       quotas__isnull=False).distinct())
            if self.voucher.item_id and self.voucher.variation_id:
                item.available_variations = [
                    v for v in item.available_variations
                    if v.pk == self.voucher.variation_id
                ]

            item.has_variations = item.variations.exists()
            if not item.has_variations:
                if self.voucher.allow_ignore_quota or self.voucher.block_quota:
                    item.cached_availability = (Quota.AVAILABILITY_OK, 1)
                else:
                    item.cached_availability = item.check_quotas()
                item.price = self.voucher.calculate_price(item.default_price)
            else:
                for var in item.available_variations:
                    if self.voucher.allow_ignore_quota or self.voucher.block_quota:
                        var.cached_availability = (Quota.AVAILABILITY_OK, 1)
                    else:
                        var.cached_availability = list(var.check_quotas())
                    var.price = self.voucher.calculate_price(
                        var.default_price if var.
                        default_price is not None else item.default_price)

                if len(item.available_variations) > 0:
                    item.min_price = min(
                        [v.price for v in item.available_variations])
                    item.max_price = max(
                        [v.price for v in item.available_variations])

        items = [
            item for item in items
            if len(item.available_variations) > 0 or not item.has_variations
        ]
        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)

        return context