Exemplo n.º 1
0
 def get_queryset(self):
     basket_pk = self.kwargs.get("basket_pk")
     basket = generics.get_object_or_404(operations.editable_baskets(), pk=basket_pk)
     prepped_basket = operations.prepare_basket(basket, self.request)
     if operations.request_allows_access_to_basket(self.request, prepped_basket):
         return prepped_basket.all_lines()
     else:
         return self.queryset.none()
Exemplo n.º 2
0
 def get_queryset(self):
     basket_pk = self.kwargs.get('basket_pk')
     basket = get_object_or_404(operations.editable_baskets(), pk=basket_pk)
     prepped_basket = operations.prepare_basket(basket, self.request)
     if operations.request_allows_access_to_basket(self.request, prepped_basket):
         return prepped_basket.all_lines()
     else:
         return self.queryset.none()
Exemplo n.º 3
0
 def get_queryset(self):
     basket_pk = self.kwargs.get('basket_pk')
     basket = get_object_or_404(operations.editable_baskets(), pk=basket_pk)
     prepped_basket = operations.prepare_basket(basket, self.request)
     if operations.request_contains_basket(self.request, prepped_basket):
         return prepped_basket.all_lines()
     else:
         return self.queryset.none()
Exemplo n.º 4
0
    def get_queryset(self):
        qs = super(BasketList, self).get_queryset()
        if self.request.user.is_authenticated:
            qs = qs.filter(owner=self.request.user)
            mapped_with_baskets = list(
                map(
                    functools.partial(assign_basket_strategy,
                                      request=self.request), qs))
        else:  # anonymous users have max 1 basket.
            basket = get_anonymous_basket(self.request)
            mapped_with_baskets = [prepare_basket(basket, self.request)]

        return QuerySetList(mapped_with_baskets, qs)
Exemplo n.º 5
0
    def restore_object(self, attrs, instance=None):
        if instance is not None:
            return instance

        basket = attrs.get('basket')
        order_number = self.generate_order_number(basket)
        try:
            request = self.context['request']
            return self.place_order(
                order_number=order_number,
                user=request.user,
                basket=prepare_basket(basket, request),
                shipping_address=attrs.get('shipping_address'),
                shipping_method=attrs.get('shipping_method'),
                shipping_charge=attrs.get('shipping_charge'),
                billing_address=attrs.get('billing_address'),
                order_total=attrs.get('total'),
            )
        except ValueError as e:
            raise exceptions.NotAcceptable(e.message)
Exemplo n.º 6
0
    def restore_object(self, attrs, instance=None):
        if instance is not None:
            return instance

        basket = attrs.get('basket')
        order_number = self.generate_order_number(basket)
        try:
            request = self.context['request']
            return self.place_order(
                order_number=order_number,
                user=request.user,
                basket=prepare_basket(basket, request),
                shipping_address=attrs.get('shipping_address'),
                shipping_method=attrs.get('shipping_method'),
                shipping_charge=attrs.get('shipping_charge'),
                billing_address=attrs.get('billing_address'),
                order_total=attrs.get('total'),
            )
        except ValueError as e:
            raise exceptions.NotAcceptable(e.message)
Exemplo n.º 7
0
 def get_object(self, queryset=None):
     basket = super(BasketDetail, self).get_object(queryset)
     return prepare_basket(basket, self.request)
Exemplo n.º 8
0
 def get_object(self, queryset=None):
     basket = super(BasketDetail, self).get_object(queryset)
     return prepare_basket(basket, self.request)