本文整理汇总了Python中cart.Cart.get_total_price方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.get_total_price方法的具体用法?Python Cart.get_total_price怎么用?Python Cart.get_total_price使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cart.Cart
的用法示例。
在下文中一共展示了Cart.get_total_price方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cart
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import get_total_price [as 别名]
def cart(request):
_cart = Cart(request)
items = len(list(_cart.cart.item_set.all()))
item_ct = get_model_content_type(Item)
addon_ct = get_model_content_type(Addon)
products = _cart.cart.item_set.filter(content_type=item_ct)
addons = _cart.cart.item_set.filter(content_type=addon_ct)
total_price = _cart.get_total_price()
bonus_max = round(total_price * Decimal(str(0.1 / settings.DEFAULT_EXCHANGE_RATE)))
service = None
deliver_cost = None
if products:
# item could be deleted so careful
try:
service = products.all()[0].product.container.owner
deliver_cost = service.get_deliver_cost(total_price)
except ObjectDoesNotExist:
_cart.cart.item_set.all().delete()
context = {
"cart": _cart,
"kart": {
"total_price": _cart.get_total_price(),
"products": products,
"cart_items": items or None,
"addons": addons,
"bonus_max": int(bonus_max),
"service": service,
"deliver_cost": int(deliver_cost) if deliver_cost is not None else None,
},
}
return context
示例2: clean
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import get_total_price [as 别名]
def clean(self):
# deliver_date, deliver_time
dd = self.cleaned_data.get('deliver_date', None)
dt = self.cleaned_data.get('deliver_time', None)
cart = Cart(self.request)
total_price = cart.get_total_price()
item_ct = get_model_content_type(Item)
item = cart.cart.item_set.filter(content_type=item_ct)
minimal_cost = item[0].product.container.owner.minimal_cost if len(item) else 0
if total_price < minimal_cost and total_price > 0:
msg = _("Minimal cost for order is '%s' for this service, "
"you should get more items to process") % minimal_cost
self._errors['name'] = ErrorList([msg])
if all((dd, dt)):
now = datetime.now()
offset = now + timedelta(minutes=30)
st = datetime(dd.year, dd.month, dd.day, dt.hour, dt.minute, dt.second)
if st <= offset:
msg = _("You can not order in the past")
self._errors['deliver_date'] = ErrorList([msg])
return self.cleaned_data
示例3: clean_discount
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import get_total_price [as 别名]
def clean_discount(self):
discount = self.cleaned_data['discount'] or None
if discount:
if discount > self.request.user.bonus_score:
raise forms.ValidationError(
_("You can not spend more bonus points than you have")
)
cart = Cart(self.request)
price = cart.get_total_price()
threshold = settings.DEFAULT_BONUS_PAY_THRESHOLD_AMOUNT
exchange = settings.DEFAULT_EXCHANGE_RATE
msg = _(
"""Maxium discount you can get
is '%(percent)s' of '%(amount)s is %(max)s'""") % {
'percent': str(threshold * 100) + '%',
'amount': price,
'max': str(round(price * Decimal(str(threshold))))
}
if Decimal(str(discount * exchange)) > (price * Decimal(str(threshold))):
raise forms.ValidationError(msg)
if discount < 0:
raise forms.ValidationError(
_("You can not proceed negative values for discount")
)
return discount
示例4: save
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import get_total_price [as 别名]
def save(self, commit=True):
""" if not commit, please add items manual """
instance = self.instance
cart = Cart(self.request)
discount = self.cleaned_data['discount'] or 0
exchange = settings.DEFAULT_EXCHANGE_RATE
total_price = cart.get_total_price()
instance.cost = total_price # - Decimal(str(discount * exchange))
instance.discount = Decimal(str(discount * exchange))
new_user = None
if all((self.cleaned_data['is_register'], self.cleaned_data['email'])):
new_user = User.objects.create(
email=self.cleaned_data['email'],
username=self.cleaned_data['email'],
phone=self.cleaned_data['phone']
)
new_password = uuid1().hex[:6]
new_user.set_password(new_password)
new_user.save()
email = new_user.email
link = settings.SITE_URL + '/login'
login = new_user.username
send_mail(
subject=unicode(_(u"Регистрация на uzevezu.ru")),
message=unicode(settings.ORDER_REGISTER_MESSAGE % {
'password': new_password,
'login': login,
'link': link
}),
from_email=settings.EMAIL_FROM,
recipient_list=[email, ],
fail_silently=True
)
if self.request.user.is_authenticated() or new_user:
instance.client = new_user or self.request.user
super(OrderForm, self).save(commit)
is_authenticated = reduce(
lambda x,y: getattr(x, y) if hasattr(x, y) else None,
[self.request, 'user', 'is_authenticated']
)
if not is_authenticated():
# send sms
sms = SMSLogger.objects.create(
provider='disms',
phone=self.cleaned_data['phone'],
text=settings.ANONYMOUS_ORDER_MESSAGE
)
sms.send_message()
sms.save()
return self.instance
# reloading bonus score
self.request.user.reload_bonus_score(rebuild=True)
return self.instance
示例5: clean_deliver_cost
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import get_total_price [as 别名]
def clean_deliver_cost(self):
deliver_cost = self.cleaned_data['deliver_cost']
_cart = Cart(self.request)
item_ct = get_model_content_type(Item)
items = _cart.cart.item_set.filter(content_type=item_ct)
if items:
owner = items[0].product.container.owner
dcost = owner.get_deliver_cost(_cart.get_total_price())
if dcost > deliver_cost:
raise forms.ValidationError(
_("Deliver cost should not be lower than"
"'%s' value") % dcost
)
return deliver_cost
示例6: cart
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import get_total_price [as 别名]
def cart(request):
_cart = Cart(request)
item_ct = get_model_content_type(Item)
products = _cart.cart.item_set.filter(content_type=item_ct)
context = {
'cart': _cart, 'total_price': _cart.get_total_price(),
'products': products,
}
if products:
service = products.all()[0].product.container.owner
return {
'redirect': 'catalog:service-page',
'redirect-args': (service.pk,)
}
else:
context.update({
'_template': 'catalog/cart.html'
})
return context
示例7: cart_detail
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import get_total_price [as 别名]
def cart_detail(request):
if request.method == 'GET':
# Get the shopping cart
cart = Cart(request)
print cart
# Get delivery type (home or store)
delivery_type = "store"
if request.is_ajax():
delivery_type = request.POST['delivery_type']
# Load the user profile attributes
try:
userprofile = UserProfile.objects.get(user=request.user)
except:
userprofile = None
# Find the largest postage price and set it as delivery price
total_delivery_price = 0
# Iterate over all of the items in the cart
for item in cart:
# If the item is out of stock, remove it
if item['product'].quantity == 0:
cart_remove(request, item['product'].id)
else:
if item['product'].postage_price > total_delivery_price:
total_delivery_price = item['product'].postage_price
item['update_quantity_form'] = CartAddProductForm(
update=True,
current_quantity=item['quantity'],
total_quantity=item['product'].quantity
)
print delivery_type
print total_delivery_price
if delivery_type == "store":
total_delivery_price = 0
print total_delivery_price
return render(request, 'ArtVillage/detail.html',
{'cart': cart, 'total_delivery_price': total_delivery_price, 'total_with_delivery':
cart.get_total_price() + total_delivery_price, 'delivery_type': delivery_type, 'userprofile': userprofile})
else:
# Get the shopping cart
cart = Cart(request)
print cart
# Get delivery type (home or store)
delivery_type = "store"
if request.is_ajax():
delivery_type = request.POST['delivery_type']
# Load the user profile attributes
try:
userprofile = UserProfile.objects.get(user=request.user)
except:
userprofile = None
# Find the largest postage price and set it as delivery price
total_delivery_price = 0
# Iterate over all of the items in the cart
for item in cart:
# If the item is out of stock, remove it
if item['product'].quantity == 0:
cart_remove(request, item['product'].id)
else:
if item['product'].postage_price > total_delivery_price:
total_delivery_price = item['product'].postage_price
item['update_quantity_form'] = CartAddProductForm(
update=True,
current_quantity=item['quantity'],
total_quantity=item['product'].quantity
)
print delivery_type
print total_delivery_price
if delivery_type == "store":
total_delivery_price = 0
print total_delivery_price
return render(request, 'ArtVillage/shopping_cart_table.html',
{'cart': cart, 'total_delivery_price': total_delivery_price, 'total_with_delivery':
cart.get_total_price() + total_delivery_price, 'delivery_type': delivery_type, 'userprofile': userprofile})