Example #1
0
    def post(self, request):
        serializer = self.serializer_class(data=request.data)
        if serializer.is_valid():
            serializer.save()
            msg = "Product " + serializer.validated_data[
                "name"] + " create successFully"
            return response(condition=1,
                            message=msg,
                            status=status.HTTP_200_OK)

        else:
            return response(condition=0,
                            message=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
Example #2
0
    def post(self, request):
        serializer = self.serializer_class(data=request.data)
        pass
        if serializer.is_valid():
            Ucustomer = request.user
            customer = Customer.objects.prefetch_related(
                "product").prefetch_related("_file").get(user=Ucustomer)
            filerequested = None
            try:
                filerequested = File.objects.get(
                    id=serializer.validated_data["id"])
            except:
                msg = "this File is not exist"
                return response(condition=0,
                                message=msg,
                                status=status.HTTP_400_BAD_REQUEST)
            Uadmin = filerequested.product.store.admin.user
            customer_file_list = customer._file.all()
            customer_product_file = []
            for product in customer.product.all():
                customer_product_file.append(list(product.file))
            customer_all_file = list(
                customer_file_list) + customer_product_file
            if filerequested in customer_all_file:
                msg = "you  Buy " + str(
                    serializer.validated_data["id"]) + " File before"
                return response(condition=1,
                                message=msg,
                                status=status.HTTP_202_ACCEPTED)
            elif filerequested.fee > Ucustomer.credit:
                msg = "you  dont have enough money sharge your account"
                return response(condition=0,
                                message=msg,
                                status=status.HTTP_402_PAYMENT_REQUIRED)
            else:
                Uadmin.credit += filerequested.fee
                Ucustomer.credit -= filerequested.fee
                customer._file.add(filerequested)
                customer.save()
                Ucustomer.save()
                Uadmin.save()
                msg = "File Buy successFully "
                return response(condition=1,
                                message=msg,
                                status=status.HTTP_200_OK)

        else:
            return response(condition=0,
                            message=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
Example #3
0
 def post(self, request):
     serializer = self.serializer_class(data=request.data,
                                        context={"request": request})
     if serializer.is_valid():
         serializer.save()
         msg = "the store with name " + serializer.validated_data[
             'name'] + "create successFully"
         return response(condition=1,
                         message=msg,
                         status=status.HTTP_200_OK)
     else:
         return response(condition=0,
                         message=serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
Example #4
0
    def post(self, request):
        serializer = self.serializer_class(data=request.data)
        if serializer.is_valid():
            product = serializer.validated_data["product"]
            files = File.objects.filter(product=product)
            files = FileShowListSerializer(files, many=True)
            msg = {"Files": files.data}
            return response(condition=1,
                            message=msg,
                            status=status.HTTP_200_OK)

        else:
            return response(condition=0,
                            message=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
Example #5
0
    def post(self, request):
        serializer = self.serializer_class(data=request.data)
        if serializer.is_valid():
            store = serializer.validated_data["store"]
            products = Product.objects.filter(store=store)
            products = ProductShowListSerializer(products, many=True)
            msg = {"products": products.data}
            return response(condition=1,
                            message=msg,
                            status=status.HTTP_200_OK)

        else:
            return response(condition=0,
                            message=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
Example #6
0
    def get(self, request):
        customer = request.user.customer
        stores = customer.store.prefetch_related("product").prefetch_related(
            "product__file").all()
        Cstores = []
        for store in stores:
            products = []
            for product in store.product.all():
                files = []
                for file in product.file.all():
                    files.append(FileSerializer(file).data)
                products.append({"product_name": product.name, "files": files})
            Cstores.append({"storename": store.name, "products": products})

        products = []
        for product in customer.product.all():
            files = []
            for file in product.file.all():
                files.append(FileSerializer(file).data)
                products.append({"product_name": product.name, "files": files})

        files = []
        for file in customer._file.all():
            files.append(FileSerializer(file).data)

        msg = {"stores": Cstores, "product": products, "singleFiles": files}
        return response(condition=1, message=msg, status=status.HTTP_200_OK)
Example #7
0
    def post(self, request):
        serializer = self.serializer_class(data=request.data)
        if serializer.is_valid():
            Ucustomer = request.user
            customer = Ucustomer.customer

            productRequested = serializer.validated_data["id"]
            try:
                productRequested = Product.objects.get(
                    id=serializer.validated_data["id"])
            except:
                msg = "this Product is not exist"
                return response(condition=0,
                                message=msg,
                                status=status.HTTP_400_BAD_REQUEST)
            customerProduct = customer.product.all()
            Uadmin = productRequested.store.admin.user
            if productRequested in customerProduct:
                msg = "you  Buy " + str(
                    serializer.validated_data["id"]) + " Product before"
                return response(condition=1,
                                message=msg,
                                status=status.HTTP_202_ACCEPTED)
            elif productRequested.fee > Ucustomer.credit:
                msg = "you  dont have enough money sharge your account"
                return response(condition=0,
                                message=msg,
                                status=status.HTTP_402_PAYMENT_REQUIRED)
            else:
                Uadmin.credit += productRequested.fee
                Ucustomer.credit -= productRequested.fee
                customer.product.add(productRequested)
                customer.save()
                Ucustomer.save()
                Uadmin.save()
                msg = "Product Buy successFully "
                return response(condition=1,
                                message=msg,
                                status=status.HTTP_200_OK)

        else:
            return response(condition=0,
                            message=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
Example #8
0
 def get(self, request):
     categories = Category.objects.all()
     serializer = CategourySerializer(categories, many=True)
     return response(condition=1,
                     message={"list_of_categories": serializer.data},
                     status=status.HTTP_200_OK)
Example #9
0
    def post(self, request):
        serializer = self.serializer_class(data=request.data)
        if serializer.is_valid():
            try:
                store = serializer.validated_data["name"]
                store = Store.objects.get(name=store)
            except:
                msg = "this store is not exist"
                return response(condition=0,
                                message=msg,
                                status=status.HTTP_400_BAD_REQUEST)

            Cuser = request.user
            customer = Cuser.customer
            customrt_stores = customer.store.all()
            if store in customrt_stores:
                storeCustomer = StoreCustomer.objects.filter(
                    store=store, customer=customer).get()
                if storeCustomer.expire_time < date.today():
                    Cuser.credit -= store.price
                    auser = store.admin.user
                    auser.credit += store.price
                    Cuser.save()
                    auser.save()
                    now = timezone.now()
                    storeCustomer.expire_time = timezone.datetime(
                        year=now.year + 2, month=now.month, day=now.day)
                    storeCustomer.save()
                    msg = "membership Update successFully "
                    return response(condition=1,
                                    message=msg,
                                    status=status.HTTP_200_OK)
                else:
                    msg = "you  get membership of " + serializer.validated_data[
                        "name"] + " store before"
                    return response(condition=1,
                                    message=msg,
                                    status=status.HTTP_202_ACCEPTED)

            if customer.user.credit < store.price:
                msg = "you  dont have enough money sharge your account"
                return response(condition=0,
                                message=msg,
                                status=status.HTTP_402_PAYMENT_REQUIRED)

            Cuser.credit -= store.price
            auser = store.admin.user
            auser.credit += store.price
            Cuser.save()
            auser.save()
            now = timezone.now()
            expire_time = timezone.datetime(year=now.year + 2,
                                            month=now.month,
                                            day=now.day)
            StoreCustomer.objects.create(customer=customer,
                                         store=store,
                                         expire_time=expire_time)
            customer.save()
            msg = "membership Buy successFully "
            return response(condition=1,
                            message=msg,
                            status=status.HTTP_200_OK)

        else:
            return response(condition=0,
                            message=serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
Example #10
0
 def get(self, request):
     stores = Store.objects.all()
     serlilizer = StoreSerializer(stores, many=True)
     msg = {"Stores list": serlilizer.data}
     return response(condition=1, message=msg, status=status.HTTP_200_OK)