本文整理汇总了Python中orders.models.Order.user方法的典型用法代码示例。如果您正苦于以下问题:Python Order.user方法的具体用法?Python Order.user怎么用?Python Order.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类orders.models.Order
的用法示例。
在下文中一共展示了Order.user方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import user [as 别名]
def get(self, request, *args, **kwargs ):
get_data = super(CheckoutView, self).get(request, *args, **kwargs)
cart = self.get_object()
user_checkout_id = request.session.get("user_checkout_id")
if user_checkout_id != None:
user_checkout = UserCheckout.objects.get(id=user_checkout_id)
billing_address_id = request.session.get("billing_address_id")
shipping_address_id = request.session.get("shipping_address_id")
if billing_address_id == None or shipping_address_id == None:
return redirect('order_address')
else:
billing_address = UserAddress.objects.get(id=billing_address_id)
shipping_address = UserAddress.objects.get(id=shipping_address_id)
try:
new_order_id = request.session['order_id']
new_order = Order.objects.get(id=new_order_id)
except:
new_order = Order()
request.session["order_id"] = new_order.id
# new_order.cart = cart
new_order.user = user_checkout
new_order.billing_address = billing_address
new_order.shipping_address = shipping_address
new_order.save()
return get_data
示例2: create_order
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import user [as 别名]
def create_order(request,cart, delivery=None):
subtotal = cart.total_price
order = Order()
order.user = request.user
delivery = Delivery.objects.all()[0]
order.delivery = delivery
order.total = subtotal + Decimal(order.delivery.price)
order.save()
for pro in cart:
line = OrderLine()
line.order = order
line.product = pro.item
line.quantity = pro.quantity
if pro.color:
line.color = Color.objects.get(pk=pro.color)
if pro.size:
line.size = Size.objects.get(pk=pro.size)
line.line_price = pro.item.total_price() * pro.quantity
line.save()
request.session['order_pk'] = order.pk
return order
示例3: create_order
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import user [as 别名]
def create_order(request,basket):
subtotal = 0
for song_price in basket:
subtotal += song_price.song.price
if subtotal == 0:
return
order = Order()
order.user = request.user
order.total = subtotal
order.basket_id = request.session['cart_id']
order.save()
for song in basket:
line = OrderLine()
line.order = order
line.songs_pk_id = song.song.pk
line.songs_name = song.song.full_name
line.line_price = song.song.price
line.save()
return order
示例4: checkout
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import user [as 别名]
def checkout(request):
## using the session we created during carts to collect the cart_id.
try:
the_id = request.session['cart_id']
cart= Cart.objects.get(id= the_id)
print cart
except :
the_id= None
## Redirects to a url that we had initially configured in django urls page
return HttpResponseRedirect(reverse("cart"))
# Creating a new instance if there is no order present. This instance will be saved as the
# new order.
try:
new_order = Order.objects.get(cart=cart)
except Order.DoesNotExist:
new_order = Order()
new_order.cart = cart
new_order.user = request.user
new_order.order_id = id_generator()
new_order.save()
# it will return the user back to the cart
except:
return HttpResponseRedirect(reverse("cart"))
# If the order is indicated as finished the cart will be deleted as well as
# resetting the total number of items back to zero.
if new_order.status== "Finished":
del request.session['cart_id']
del request.session['items_total']
return HttpResponseRedirect(reverse("cart"))
context={}
return render(request, "products/home.html", context)
示例5: checkout
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import user [as 别名]
def checkout(request):
try:
the_cart_id = request.session['cart_id']
cart = Cart.objects.get(id=the_cart_id)
subbies = CartItem.subbie_type.filter(cart=cart)
singles = CartItem.single_type.filter(cart=cart)
cart_items = CartItem.objects.filter(cart=cart)
except:
the_cart_id = None
return HttpResponseRedirect(reverse("view_cart"))
try:
user = request.user
except:
user = None
try:
new_order = Order.objects.get(cart=cart)
except Order.DoesNotExist:
new_order = Order()
new_order.cart = cart
new_order.order_id = id_generator()
new_order.save()
except:
new_order = None
return HttpResponseRedirect(reverse("view_cart"))
if request.user.is_authenticated():
new_order.user = request.user
print new_order.user
print "we gota new order user"
new_order.total = cart.total
new_order.shipping = cart.shipping_total
if new_order.coupon:
coupon = new_order.coupon
percent_discount = coupon.percent_discount
new_total = new_order.total - new_order.total * (float(percent_discount) / 100)
print new_total
new_order.total = new_total
new_order.save()
pay_form = PayForm()
order = new_order
subgo = False
singo = False
paygo = False
usergo = False
if subbies and singles:
for sub in subbies:
if sub.recipient:
subgo = True
else:
subgo = False
if order.main_recipient:
singo = True
else:
singo = False
if subgo == True and singo == True:
paygo = True
else:
paygo = False
elif not subbies and singles:
if order.main_recipient:
singo = True
else:
singo = False
if subgo == False and singo == True:
paygo = True
else:
paygo = False
elif subbies and not singles:
for sub in subbies:
if sub.recipient:
subgo = True
else:
subgo = False
if subgo == True and singo == False:
paygo = True
else:
paygo = False
# check user status
user = request.user
if user.is_authenticated():
usergo = True
elif singles and not subbies:
usergo = True
else:
usergo = False
if request.POST:
#.........这里部分代码省略.........
示例6: new_order
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import user [as 别名]
def new_order(atg_order, tinla_profile, client):
# Ensure that there is no profile with this atg login
map_entry = None
try:
map_entry = AtgOrderMigrationMap.objects.select_related('order').get(
atg_order = atg_order.order.order)
log.info("Already migrated %s, skipping new_order" % atg_order.order.order)
return map_entry.order
except AtgOrderMigrationMap.DoesNotExist:
pass
# create new order
order = Order()
order.user = tinla_profile
order.state = get_order_state(atg_order.order.order_state)
order.timestamp = atg_order.order.atg_creation_date
order.payment_realized_on = atg_order.order.atg_submitted_date
order.modified_on = atg_order.order.last_modified_date
order.reference_order_id = atg_order.order.order
order.client = client
order.save()
# delivery info
shipping = DcsppShipGroup.objects.filter(order_ref = atg_order.order.order)
if shipping:
shipping = shipping[0]
dcspp_addr = DcsppShipAddr.objects.filter(shipping_group=shipping.shipping_group)
if dcspp_addr:
shipping = dcspp_addr[0]
if shipping:
addr = Address()
addr.profile = tinla_profile
addr.account = client.account_set.all()[0]
addr.first_name = shipping.first_name
addr.last_name = shipping.last_name
addr.phone = shipping.phone_number
addr.email = shipping.email
addr.pincode = shipping.postal_code
country, state, city = '', '', ''
try:
if shipping.county: country = get_country(shipping.county)
if shipping.state and country: state = get_state(shipping.state.state_name, country)
if shipping.city and state: city = get_city(shipping.city, state)
if country: addr.country = country
if state: addr.state = state
if city: addr.city = city
except:
pass
addr.save()
del_info = DeliveryInfo()
del_info.address = addr
del_info.order = order
del_info.save()
order_items = atg_order.order.dcspporderitem_set.all()
list_price_total, shipping_charges = Decimal(0), Decimal(0)
for atg_oi in order_items:
oi = OrderItem()
ci = atg_oi.commerce_items
oi.order = order
oi.state = get_order_state(ci.state)
try:
src = SellerRateChart.objects.get(sku=ci.sku.sku.sku_id, seller__client = client)
oi.seller_rate_chart = src
except SellerRateChart.DoesNotExist:
pass
oi.list_price = ci.amount_info.list_price
list_price_total += ci.amount_info.list_price
oi.sale_price = ci.amount_info.sale_price
del_item = FtbShipitemRel.objects.filter(relationship__commerce_item = atg_oi)
if del_item:
del_item = del_item[0]
oi.shipping_charges = del_item.shipping_cost
shipping_charges += del_item.shipping_cost
"shipping found for ", atg_order.order
oi.qty = ci.quantity
oi.save()
# amount info
order_discount_total = Decimal(str(atg_order.ord_misc_field1))
sale_price_total = atg_order.order.price_info.raw_subtotal
total_order_shipping = atg_order.order.price_info.shipping + shipping_charges
order.shipping_charges = total_order_shipping
order.list_price_total = list_price_total
order.total = sale_price_total
order.payable_amount = sale_price_total + total_order_shipping - order_discount_total
order.save()
print order.id
print order.reference_order_id
#.........这里部分代码省略.........
示例7: process_order
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import user [as 别名]
def process_order(self, pyOrder, payment_form):
"""
Takes the following steps:
1. Locks the products in the cart, read-only access only (TBD, I have no idea how to do this ATM)
2. Creates an Order instance from the form data in this checkout process, and validates it (it should checkout
ok, if it doesn't there was a bug in my forms.
3. Authorize credit-card, payment information (the payment form will have a hidden containing the amount to
put on the card. This way the number the user sees and the number I charge are guaranteed to be the same.
4. Submit the order (save it)
5. Decrement product stock
6. Unlock the products that were locked in step 1
7. Redirect the user to a receipt page
"""
order = Order() # db class
if not payment_form.is_valid():
return False
# link user information, even if that user is a guest (lazy) account. They'll need this information set in
# order to view their order receipt at the end of the process.
order.user = self.request.user
order.first_name = pyOrder.first_name
order.last_name = pyOrder.last_name
order.email = pyOrder.email
order.phone = pyOrder.phone
order.contact_method = pyOrder.contact_method
order.shipping_method = pyOrder.shipping_method
order.shipping_charge = pyOrder.shipping_charge
order.save()
# save the payment information
payment_form.save(order)
shipping_address = pyOrder.shipping_address.as_address(OrderShippingAddress)
shipping_address.order = order
shipping_address.save()
billing_address = pyOrder.billing_address.as_address(OrderBillingAddress)
billing_address.order = order
billing_address.save()
for order_item in pyOrder.items:
order_item.order = order
order_item.full_clean()
order_item.save()
# decrement stock for products
if order_item.is_product():
in_stock = order_item.item.quantity
order_item.item.quantity = max(0, in_stock - order_item.quantity)
order_item.item.save()
# mark wish list items as sold
wishlist_links = order_item.cart_item.wishlist_links.all()
for link in wishlist_links:
link.wishlist_item.order_item = order_item
link.wishlist_item.full_clean()
link.wishlist_item.save()
for (name, rate, total) in pyOrder.tax_breakdown():
orderTax = OrderTax(name=name, rate=rate, total=total, order=order)
orderTax.save()
# save the order-id in the session dictionary
self.save('order', order.id)
return True