def thanksView(request): context=base_context_genre(request) order = request.GET.get('order') if not order: return HttpResponseRedirect('/') context.update({'order': order}) return render(request, 'account/thanks.html', context=context)
def orderView(request): form = OrderForm() context = base_context_genre(request) if request.method == "POST": print(request.POST) product_id_list = request.POST.getlist('product_id') option_id_list = request.POST.getlist('option_id') count_list = request.POST.getlist('count') product_list = Variation.objects.filter(id__in=map(lambda x: int(x), product_id_list)) context.update(products_json(product_list, count_list)) context.update( {'order_products': zip( product_id_list, option_id_list, count_list )}) if 'create' in request.POST: form = OrderForm(request.POST) print("BEFORE") order_id = create_order(request, form) print("AFTER") if order: return HttpResponseRedirect(reverse('thanks')+f"?order={order_id}") context.update( {'message': {'text': 'Не удалось создать заказ! :(', 'type': 'error'}}) context.update( {'form': form }) return render(request, 'account/order.html', context=context)
def LogInView(request): form = LogInForm(request.POST or None) context = base_context_genre(request) context.update( {'form': form }) if request.method == "POST": next_page_url = request.GET.get('next') if form.is_valid(): client_data = form.cleaned_data user = authenticate(username=client_data['login'], password=client_data['password']) if user is not None: login(request, user) return HttpResponseRedirect(next_page_url or '/') return render(request, 'account/login.html', context=context) return render(request, 'account/login.html', context=context)
def CartView(request): if request.method == "POST" and "remove" in request.POST: option_id = int(request.POST['remove']) option = Options.objects.get(pk=option_id) try: delete_item = Cart.objects.get( user=request.user, product=option.variation, option=option ) delete_item.delete() except Cart.DoesNotExist: logger.warning("No have cart item with product option id '%s'" % str(option_id)) cart_items = get_cart_items(request) context = base_context_genre(request) context.update({ 'cart_items': cart_items, 'total': round(sum(map(itemgetter('totalPrice'), cart_items)), 2), 'xhr_url': reverse('cart_count') }) return render(request, "account/cart.html", context=context)
def AccountView(request): context = base_context_genre(request) return render(request, 'account/account.html', context=context)