本文整理汇总了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函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:ikebrown,项目名称:simple-django-deployment,代码行数:33,代码来源:views.py
示例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
开发者ID:alainwolf,项目名称:openbroadcast.org,代码行数:28,代码来源:checkout.py
示例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)
开发者ID:bbelchak,项目名称:django-shop,代码行数:7,代码来源:util.py
示例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()
开发者ID:hnejadi,项目名称:django-shop-viveum,代码行数:7,代码来源:tests.py
示例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()
}
开发者ID:alainwolf,项目名称:openbroadcast.org,代码行数:7,代码来源:shop_tags.py
示例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)
开发者ID:dinoperovic,项目名称:django-shop-catalog,代码行数:7,代码来源:views.py
示例7: get_context
def get_context(self, context):
request = context['request']
cart = get_or_create_cart(request)
cart.update(request)
return {
'cart': cart
}
开发者ID:alrvivas,项目名称:CampoApp2,代码行数:7,代码来源:shop_tags.py
示例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()
开发者ID:sephii,项目名称:django-shop,代码行数:7,代码来源:cart.py
示例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
}
开发者ID:sarva,项目名称:django-shop,代码行数:8,代码来源:shop_tags.py
示例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)
开发者ID:katomaso,项目名称:django-shop,代码行数:8,代码来源:util.py
示例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
开发者ID:sephii,项目名称:django-shop,代码行数:8,代码来源:cart.py
示例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 ''
开发者ID:zdanozdan,项目名称:mshop,代码行数:9,代码来源:mikran_tags.py
示例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"))
开发者ID:akarca,项目名称:django-shop,代码行数:9,代码来源:cart.py
示例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()
开发者ID:jrief,项目名称:django-shop-productvariations,代码行数:9,代码来源:views.py
示例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
开发者ID:ojii,项目名称:cmsplugin-shop,代码行数:9,代码来源:cms_plugins.py
示例16: create_order_object_from_cart
def create_order_object_from_cart(self):
"""
This will create an Order object form the current cart, and will pass
a reference to the Order on either the User object or the session.
"""
cart = get_or_create_cart(self.request)
order = Order.objects.create_from_cart(cart)
request = self.request
add_order_to_request(request, order)
开发者ID:reason-systems,项目名称:django-shop,代码行数:9,代码来源:checkout.py
示例17: post
def post(self, *args, **kwargs):
#it starts similar to the original post method
product_id = self.request.POST['add_item_id']
product_quantity = self.request.POST.get('add_item_quantity')
if not product_quantity:
product_quantity = 1
product = Product.objects.get(pk=product_id)
cart_object = get_or_create_cart(self.request)
#now we need to find out which options have been chosen by the user
option_ids = []
text_option_ids = {} # A dict of {TextOption.id:CartItemTextOption.text}
for key in self.request.POST.keys():
if key.startswith('add_item_option_group_'):
option_ids.append(self.request.POST[key])
elif key.startswith('add_item_text_option_'):
id = key.split('add_item_text_option_')[1]
text_option_ids.update({id:self.request.POST[key]})
#now we need to find out if there are any cart items that have the exact
#same set of options
qs = CartItem.objects.filter(cart=cart_object).filter(product=product)
found_cartitem_id = None
merge = False
for cartitem in qs:
# for each CartItem in the Cart, get it's options and text options
cartitemoptions = CartItemOption.objects.filter(
cartitem=cartitem, option__in=option_ids
)
cartitemtxtoptions = CartItemTextOption.objects.filter(
text_option__in=text_option_ids.keys(),
text__in=text_option_ids.values()
)
if (len(cartitemoptions) + len(cartitemtxtoptions)
== (len(option_ids) + len(text_option_ids))):
found_cartitem_id = cartitem.id
merge = True
break
#if we found a CartItem object that has the same options, we need
#to select this one instead of just any CartItem that belongs to this
#cart and this product.
if found_cartitem_id:
qs = CartItem.objects.filter(pk=found_cartitem_id)
cart_item = cart_object.add_product(
product, product_quantity, merge=merge, queryset=qs)
if isinstance(product, Cigarette):
try:
cart_object.add_product(product.cartridge, 0)
for accessory in product.accessories.all():
cart_object.add_product(accessory, 0)
except Cartridge.DoesNotExist, AttributeError:
pass
开发者ID:clincher,项目名称:ecigar,代码行数:56,代码来源:views.py
示例18: post
def post(self, request, id, *args, **kwargs):
split_template = get_object_or_404(SplitTemplate, id=id)
split_form = UserSplitForm(split_template, request.POST)
# Make sure we empty the cart
cart = get_or_create_cart(request, save=True)
cart.delete()
cart = get_or_create_cart(request, save=True)
if split_form.is_valid():
for key, product_qtty in split_form.cleaned_data.iteritems():
if key.startswith('product_'):
product_id = key.lstrip('product_')
product = get_object_or_404(Product, id=product_id)
cart.add_product(product, product_qtty)
cart.save()
return redirect(reverse('cart'))
开发者ID:la-coroutine,项目名称:o3p,代码行数:19,代码来源:views.py
示例19: test_having_empty_session_cart_and_filled_database_cart_returns_database_cart
def test_having_empty_session_cart_and_filled_database_cart_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)
product = Product.objects.create(name='pizza', slug='pizza', unit_price=0)
CartItem.objects.create(cart=database_cart, quantity=1, product=product)
ret = get_or_create_cart(self.request)
self.assertNotEqual(ret, None)
self.assertEqual(ret, database_cart)
self.assertNotEqual(ret, self.cart)
开发者ID:katomaso,项目名称:django-shop,代码行数:10,代码来源:util.py
示例20: post
def post(self, *args, **kwargs):
#it starts similar to the original post method
product_id = self.request.POST['add_item_id']
product_quantity = self.request.POST.get('add_item_quantity')
if not product_quantity:
product_quantity = 1
product = Product.objects.get(pk=product_id)
cart_object = get_or_create_cart(self.request, save=True)
#now we need to find out which options have been chosen by the user
option_ids = []
text_option_ids = {} # A dict of {TextOption.id:CartItemTextOption.text}
for key in self.request.POST.keys():
if key.startswith('add_item_option_group_'):
option_ids.append(self.request.POST[key])
elif key.startswith('add_item_text_option_'):
id = key.split('add_item_text_option_')[1]
txt = self.request.POST[key]
if txt != '':
text_option_ids.update({id:txt})
#now we need to find out if there are any cart items that have the exact
#same set of options
qs = CartItem.objects.filter(cart=cart_object).filter(product=product)
found_cartitem_id = None
merge = False
# TODO: Something funky happening with the merged qs preventing new
# carts from being created. We can live with separate line items for now...
# for cartitem in qs:
# # for each CartItem in the Cart, get it's options and text options
# cartitemoptions = CartItemOption.objects.filter(
# cartitem=cartitem, option__in=option_ids
# )
#
# cartitemtxtoptions = CartItemTextOption.objects.filter(
# text_option__in=text_option_ids.keys(),
# text__in=text_option_ids.values()
# )
#
# if len(cartitemoptions) + len(cartitemtxtoptions) == (len(option_ids) + len(text_option_ids)):
# found_cartitem_id = cartitem.id
# merge = True
# break
#if we found a CartItem object that has the same options, we need
#to select this one instead of just any CartItem that belongs to this
#cart and this product.
if found_cartitem_id:
qs = CartItem.objects.filter(pk=found_cartitem_id)
cart_item = cart_object.add_product(
product, product_quantity, merge=merge, queryset=qs)
cart_object.save()
return self.post_success(product, cart_item)
开发者ID:tcdent,项目名称:django-shop-simplevariations,代码行数:55,代码来源:views.py
注:本文中的shop.util.cart.get_or_create_cart函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论