コード例 #1
0
    def post(self, request, format=None):
        # TODO: Make it possible to create orders with options.
        # at the moment, no options are passed to this method, which means they
        # are also not created.

        data_basket = self.get_data_basket(request.data, format)
        basket = self.check_basket_permission(request,
                                              basket_pk=data_basket.pk)

        # by now an error should have been raised if someone was messing
        # around with the basket, so asume invariant
        assert(data_basket == basket)

        c_ser = self.serializer_class(
            data=request.data, context={'request': request})
        if c_ser.is_valid():
            order = c_ser.save()
            basket.freeze()
            o_ser = self.order_serializer_class(
                order, context={'request': request})
            oscarapi_post_checkout.send(
                sender=self, order=order, user=request.user,
                request=request, response=response)
            return response.Response(o_ser.data)

        return response.Response(c_ser.errors, status.HTTP_406_NOT_ACCEPTABLE)
コード例 #2
0
    def post(self, request, format=None):
        # TODO: Make it possible to create orders with options.
        # at the moment, no options are passed to this method, which means they
        # are also not created.

        basket = parse_basket_from_hyperlink(request.data, format)

        if not request_allows_access_to_basket(request, basket):
            return response.Response(
                "Unauthorized", status=status.HTTP_401_UNAUTHORIZED)

        c_ser = self.serializer_class(
            data=request.data, context={'request': request})

        if c_ser.is_valid():
            order = c_ser.save()
            basket.freeze()
            o_ser = self.order_serializer_class(
                order, context={'request': request})

            resp = response.Response(o_ser.data)

            oscarapi_post_checkout.send(
                sender=self, order=order, user=request.user,
                request=request, response=resp)
            return resp

        return response.Response(c_ser.errors, status.HTTP_406_NOT_ACCEPTABLE)
コード例 #3
0
    def post(self, request, format=None):
        # TODO: Make it possible to create orders with options.
        # at the moment, no options are passed to this method, which means they
        # are also not created.

        basket = parse_basket_from_hyperlink(request.data, format)

        if not request_allows_access_to_basket(request, basket):
            return response.Response("Unauthorized",
                                     status=status.HTTP_401_UNAUTHORIZED)

        c_ser = self.serializer_class(data=request.data,
                                      context={"request": request})

        if c_ser.is_valid():
            order = c_ser.save()
            basket.freeze()
            o_ser = self.order_serializer_class(order,
                                                context={"request": request})

            resp = response.Response(o_ser.data)

            oscarapi_post_checkout.send(
                sender=self,
                order=order,
                user=request.user,
                request=request,
                response=resp,
            )
            return resp

        return response.Response(c_ser.errors, status.HTTP_406_NOT_ACCEPTABLE)
コード例 #4
0
ファイル: views.py プロジェクト: Pard33p/vivify-backend
    def post(self, request, format=None):
        # TODO: Make it possible to create orders with options.
        # at the moment, no options are passed to this method, which means they
        # are also not created.
        email = request.query_params.get('email', None)
        print(email)
        if email is not None:
            request.user = User.objects.filter(email=email).first()

        basket = parse_basket_from_hyperlink(request.data, format)

        if not request_allows_access_to_basket(request, basket):
            return response.Response("Unauthorized",
                                     status=status.HTTP_401_UNAUTHORIZED)

        c_ser = self.serializer_class(data=request.data,
                                      context={'request': request})

        if c_ser.is_valid():
            order = c_ser.save()
            _record_products_in_order(order)
            _record_user_order(request.user, order)
            basket.freeze()
            o_ser = self.order_serializer_class(order,
                                                context={'request': request})

            resp = response.Response(o_ser.data)

            oscarapi_post_checkout.send(sender=self,
                                        order=order,
                                        user=request.user,
                                        request=request,
                                        response=resp)
            return resp

        return response.Response(c_ser.errors, status.HTTP_406_NOT_ACCEPTABLE)