def process_request(request, product: pmod.Product): plist = product.image_urls() if request.method == 'POST': form = PurchaseForm(request.POST) form.user = request.user form.product = product form.sale = request.user.get_shopping_cart() if form.is_valid(): form.commit(product) PurchaseForm(request, form.user) return HttpResponseRedirect( f'/catalog/cart/{request.user.get_shopping_cart().id}') else: form = PurchaseForm() context = { 'form': form, 'product': product, 'plist': plist, } return request.dmp.render('product.html', context)
def process_request(request, product:cmod.Product): if product is None: return redirect('/catalog/index') #remove the current object from the last_five list, if it exists #this prevents it from showing up as the current object as well as in the last_five list if product in request.last_five: request.last_five.remove(product) #add the current object to the front of the last_five list request.last_five.insert(0, cmod.Product.objects.get(id = product.id)) return request.dmp.render('detail.html', { 'product': product, 'product_images': product.image_urls(), })
def process_request(request, product: cmod.Product): form = CartForm(request, product=product) if form.is_valid(): print('form is valid') form.commit() return HttpResponseRedirect('/catalog/cart/') if product is None: return HttpResponseRedirect('/') categoryList = cmod.Category.objects.all() productList = cmod.Product.objects.all().filter(status='A') myPics = product.image_urls() for p in request.last_five: if p == product or p.status == 'I': request.last_five.remove(p) request.last_five.insert(0, product) if len(request.last_five) > 6: request.last_five.pop() # elif (request.last_five.status == 'I'): # request.last_five.pop() context = { 'product': product, 'categoryList': categoryList, 'productList': productList, 'myPics': myPics, 'form': form, } return request.dmp.render('details.html', context, )
def process_request(request, product: cmod.Product = None): print(product, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") if product is None: return HttpResponseRedirect('/catalog/index') picList = product.image_urls().order_by('id') for p in picList: print(p.filename) type = product.TITLE quant = product.get_quantity() name = cmod.Category.objects.get(id=product.category_id).name user = request.user if product in request.last_five: request.last_five.remove(product) request.last_five.insert(0, product) if len(request.last_five) > 6: request.last_five.pop() form = BuyForm(request, prod=product) if form.is_valid(): if request.user.is_authenticated != True: return HttpResponseRedirect('/account/login') form.commit(product) return HttpResponseRedirect('/catalog/cart') form.submit_text = 'Add to Cart' context = { # sent to index.html: 'form': form, 'quant': quant, 'type': type, 'product': product, 'name': name if name is not None else "All Products", 'catID': product.category, 'pictures': picList, # sent to index.html and index.js: } return request.dmp.render('details.html', context)