Esempio n. 1
0
    def post(self, request):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        product = Product()
        product.user = request.user
        product.price = float(serializer.data.get('price'))
        product.currency = serializer.data.get('currency')
        product.title = serializer.data.get('title')
        product.description = serializer.data.get('description')
        product.category = Category.objects.get(id=1)
        product.time = serializer.data.get('time')
        product.length = 0
        product.width = 0
        product.height = 0
        product.weight = 0
        product.request = 1
        product.accept = 0
        product.save()

        requested = Request()
        requested.seller = serializer.validated_data['seller']
        requested.buyer = request.user
        requested.product = product
        requested.save()

        assets = serializer.data.get('assets')
        if assets:
            for url in assets:
                asset = Asset(product=product, url=url)
                asset.save()
        ItemRequest_Notification(requested.seller, request.user, product)
        ItemRequest_mail(requested.seller, request.user, product)

        return Response(
            {
                "result": True,
                "data": {
                    "Msg": "Item Request created",
                    "Request_id": requested.id,
                }
            },
            status=status.HTTP_201_CREATED)
Esempio n. 2
0
    def post(self, request):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        product = Product()
        product.user = request.user
        product.category = serializer.validated_data['category']
        product.price = float(serializer.data.get('price'))
        product.currency = serializer.data.get('currency')
        product.title = serializer.data.get('title')
        product.description = serializer.data.get('description')
        product.time = serializer.data.get('time')
        product.length = serializer.data.get('length')
        product.width = serializer.data.get('width')
        product.height = serializer.data.get('height')
        product.weight = serializer.data.get('weight')
        product.save()

        assets = serializer.data.get('assets')
        if assets:
            for url in assets:
                asset = Asset(product=product, url=url)
                asset.save()

        tags = serializer.data.get('tag')
        if tags:
            for t in tags:
                tag = HashTags(product=product, tag=t)
                tag.save()
        # ProductPost_Notification(user)
        return Response(
            {
                "result": True,
                "data": {
                    "Msg": "product created",
                    "product_id": product.id,
                }
            },
            status=status.HTTP_201_CREATED)
Esempio n. 3
0
def product_add_view(request):
    if request.POST.get('book_id'):
        product = Product.objects.get(id=request.POST.get('book_id'))
        if request.POST.get('username'):
            product.price = request.POST.get('username')
        else:
            product.price = '0'
        if request.POST.get('email'):
            product.title = request.POST.get('email')
        else:
            product.title = 'No Title'
        if not request.POST.get('name'):
            product.currency = '$'
        else:
            product.currency = request.POST.get('name')
        if request.POST.get('active'):
            product.available = request.POST.get('active')
        else:
            product.available = 'True'
        if request.POST.get('address'):
            product.description = request.POST.get('address')
        else:
            product.description = 'No Description'
        product.user.email = request.POST.get('over')
        if request.POST.get('create'):
            product.created_at = request.POST.get('create')
        else:
            product.created_at = datetime.datetime.now()
        if request.POST.get('last'):
            product.updated_at = request.POST.get('last')
        else:
            product.updated_at = datetime.datetime.now()
        product.save()
        return HttpResponseRedirect('/admin/products-list')

    else:
        product = Product()
        if request.POST.get('username'):
            product.price = request.POST.get('username')
        else:
            product.price = '0'
        if request.POST.get('email'):
            product.title = request.POST.get('email')
        else:
            product.title = 'No Title'
        if not request.POST.get('name'):
            product.currency = '$'
        else:
            product.currency = request.POST.get('name')
        product.available = 'True'
        if request.POST.get('address'):
            product.description = request.POST.get('address')
        else:
            product.description = 'No Description'
        product.user.email = request.POST.get('over')
        if request.POST.get('create'):
            product.created_at = request.POST.get('create')
        else:
            product.created_at = datetime.datetime.now()
        if request.POST.get('last'):
            product.updated_at = request.POST.get('last')
        else:
            product.updated_at = datetime.datetime.now()
        product.save()
        return HttpResponseRedirect('/admin/products-list')
    return HttpResponseRedirect('/admin/products-list')