Exemplo n.º 1
0
Arquivo: cart.py Projeto: akuks/pretix
 def _extend_existing(self, expiry):
     # Extend this user's cart session to 30 minutes from now to ensure all items in the
     # cart expire at the same time
     # We can extend the reservation of items which are not yet expired without risk
     CartPosition.objects.current.filter(
         user_cart_q(self.request) & Q(event=self.request.event) & Q(expires__gt=now())
     ).update(expires=expiry)
Exemplo n.º 2
0
Arquivo: cart.py Projeto: akuks/pretix
    def post(self, request, *args, **kwargs):
        if request.event.presale_start and now() < request.event.presale_start:
            messages.error(request, _('The presale period for this event has not yet started.'))
            return redirect(self.get_failure_url())
        if request.event.presale_end and now() > request.event.presale_end:
            messages.error(request, _('The presale period has ended.'))
            return redirect(self.get_failure_url())

        self.items = self._items_from_post_data()

        # We do not use LoginRequiredMixin here, as we want to store stuff into the
        # session before redirecting to login
        if not request.user.is_authenticated() and 'guest_email' not in request.session:
            request.session['cart_tmp'] = json.dumps(self.items)
            return redirect_to_login(
                self.get_success_url(), reverse('presale:event.checkout.login', kwargs={
                    'organizer': request.event.organizer.slug,
                    'event': request.event.slug,
                }), 'next'
            )

        existing = CartPosition.objects.current.filter(user_cart_q(self.request) & Q(event=self.request.event)).count()
        if sum(i[2] for i in self.items) + existing > int(self.request.event.settings.max_items_per_order):
            # TODO: i18n plurals
            self.error_message(self.error_messages['max_items'] % self.request.event.settings.max_items_per_order)
            return redirect(self.get_failure_url())

        return self.process()
Exemplo n.º 3
0
Arquivo: cart.py Projeto: akuks/pretix
 def _re_add_expired_positions(self):
     positions = set()
     # For items that are already expired, we have to delete and re-add them, as they might
     # be no longer available or prices might have changed. Sorry!
     for cp in CartPosition.objects.current.filter(
         user_cart_q(self.request) & Q(event=self.request.event) & Q(expires__lte=now())
     ):
         self._re_add_position(cp)
         positions.add(cp)
     return positions
Exemplo n.º 4
0
Arquivo: cart.py Projeto: akuks/pretix
    def post(self, *args, **kwargs):
        items = self._items_from_post_data()
        if not items:
            return redirect(self.get_failure_url())
        qw = user_cart_q(self.request)

        for item, variation, cnt in items:
            cw = qw & Q(item_id=item)
            if variation:
                cw &= Q(variation_id=variation)
            else:
                cw &= Q(variation__isnull=True)
            for cp in CartPosition.objects.current.filter(cw).order_by("-price")[:cnt]:
                cp.delete()

        messages.success(self.request, _('Your cart has been updated.'))
        return redirect(self.get_success_url())
Exemplo n.º 5
0
 def is_allowed(self, request: HttpRequest) -> bool:
     return CartPosition.objects.current.filter(
         user_cart_q(request) & Q(event=request.event)
     ).aggregate(sum=Sum('price'))['sum'] == 0
Exemplo n.º 6
0
 def _total_order_value(self):
     return CartPosition.objects.current.filter(
         user_cart_q(self.request) & Q(event=self.request.event)
     ).aggregate(sum=Sum('price'))['sum']