本文整理汇总了Python中shop.util.cart.get_or_create_cart函数的典型用法代码示例。如果您正苦于以下问题:Python get_or_create_cart函数的具体用法?Python get_or_create_cart怎么用?Python get_or_create_cart使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_or_create_cart函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_billingshipping_forms
def handle_billingshipping_forms(self, js_enabled, update_only, shipping_adress_form, billing_address_form):
all_valid = False
billingshipping_form = \
self.get_billing_and_shipping_selection_form()
if billingshipping_form.is_valid():
self.request.session['payment_backend'] = \
billingshipping_form.cleaned_data['payment_method']
self.request.session['shipping_backend'] = \
billingshipping_form.cleaned_data['shipping_method']
shipping_choices_form = False
payment_choices_form = False
if billingshipping_form.is_valid():
shipping_method = billingshipping_form.cleaned_data['shipping_method']
payment_method = billingshipping_form.cleaned_data['payment_method']
if self.request.method == 'POST' and js_enabled:
items = get_or_create_cart(self.request).items.all()
shipping_choices_form = self.get_backend_choices_form('shipping', shipping_method, items,
shipping_adress_form, billing_address_form)
payment_choices_form = self.get_backend_choices_form('payment', payment_method, items,
shipping_adress_form, billing_address_form)
if not update_only:
if shipping_choices_form:
if shipping_choices_form.is_valid():
self.request.session['shipping_choices'] = shipping_choices_form.cleaned_data
if payment_choices_form:
if payment_choices_form.is_valid():
self.request.session['payment_choices'] = payment_choices_form.cleaned_data
return (billingshipping_form, shipping_choices_form, payment_choices_form)
示例2: get_context_data
def get_context_data(self, **kwargs):
ctx = super(ShopTemplateView, self).get_context_data(**kwargs)
# Set the order status:
order = get_order_from_request(self.request)
if order:
order.status = Order.COMPLETED
order.save()
else:
order = Order.objects.get_latest_for_user(self.request.user)
#TODO: Is this ever the case?
ctx.update({'order': order, })
# TODO: move away from shop!!
# ctx.update({'downloads': [1], })
completed.send(sender=self, order=order)
# Empty the customers basket, to reflect that the purchase was
# completed
cart_object = get_or_create_cart(self.request)
cart_object.empty()
return ctx
示例3: test_03_passing_user_returns_proper_cart
def test_03_passing_user_returns_proper_cart(self):
self.cart.user = self.user
self.cart.save()
setattr(self.request, 'user', self.user)
ret = get_or_create_cart(self.request)
self.assertNotEqual(ret, None)
self.assertEqual(ret, self.cart)
示例4: add_product_to_cart
def add_product_to_cart(self):
product = DiaryProduct(isbn='1234567890', number_of_pages=100, name='test',
slug='test', active=True, unit_price=Decimal('1.23'))
product.save()
self.cart = get_or_create_cart(self.request, True)
self.cart.add_product(product, 1)
self.cart.save()
示例5: get_context
def get_context(self, context):
cart = get_or_create_cart(context['request'])
cart.update()
return {
'cart': cart,
'cart_items': cart.get_updated_cart_items()
}
示例6: get_context_data
def get_context_data(self, **kwargs):
context = {'object_list': []}
cart = get_or_create_cart(self.request, True)
context['object_list'] = CartModifierCode.objects.filter(cart=cart)
context.update(kwargs)
return super(CartModifierCodeCreateView, self).\
get_context_data(**context)
示例7: get_context
def get_context(self, context):
request = context['request']
cart = get_or_create_cart(request)
cart.update(request)
return {
'cart': cart
}
示例8: delete
def delete(self, *args, **kwargs):
"""
Empty shopping cart.
"""
cart_object = get_or_create_cart(self.request)
cart_object.empty()
return self.delete_success()
示例9: cart
def cart(context):
"""Inclusion tag for displaying cart summary."""
request = context['request']
cart = get_or_create_cart(request)
cart.update(request)
return {
'cart': cart
}
示例10: test_having_two_empty_carts_returns_database_cart
def test_having_two_empty_carts_returns_database_cart(self):
setattr(self.request, 'user', self.user)
setattr(self.request, 'session', {'cart_id': self.cart.pk})
database_cart = Cart.objects.create(user=self.user)
ret = get_or_create_cart(self.request)
self.assertNotEqual(ret, None)
self.assertEqual(ret, database_cart)
self.assertNotEqual(ret, self.cart)
示例11: get_context_data
def get_context_data(self, **kwargs):
# There is no get_context_data on super(), we inherit from the mixin!
ctx = {}
cart = get_or_create_cart(self.request)
cart.update(self.request)
ctx.update({'cart': cart})
ctx.update({'cart_items': cart.get_updated_cart_items()})
return ctx
示例12: render_tag
def render_tag(self, context):
cart = get_or_create_cart(context['request'])
cart.update()
context['cart'] = cart
context['cart_items': cart.get_updated_cart_items()]
formset = get_cart_item_formset(cart_items=context['cart_items'])
context['formset': formset]
return ''
示例13: success
def success(self):
"""
Generic hook by default redirects to cart
"""
if self.request.is_ajax():
cart_object = get_or_create_cart(self.request)
return HttpResponse(json.dumps({"success": True, "cart": cart_object.total_quantity}))
else:
return HttpResponseRedirect(reverse("cart"))
示例14: add_to_cart
def add_to_cart(self):
variation = self.get_variation()
product_quantity = self.request.POST.get('add_item_quantity')
if not product_quantity:
product_quantity = 1
product = self.get_object()
cart = get_or_create_cart(self.request)
cart.add_product(product, product_quantity, variation)
cart.save()
示例15: render
def render(self, context, instance, placeholder):
request = context['request']
cart = get_or_create_cart(request)
cart_items = cart.items
context.update({'cart':cart})
context.update({'cart_items':cart_items})
return context