本文整理汇总了Python中models.Order.user方法的典型用法代码示例。如果您正苦于以下问题:Python Order.user方法的具体用法?Python Order.user怎么用?Python Order.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Order
的用法示例。
在下文中一共展示了Order.user方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_order
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import user [as 别名]
def create_order(request,transaction_id):
order = Order()
checkout_form = CheckoutForm(request.POST, instance=order)
order = checkout_form.save(commit=False)
order.transaction_id = transaction_id
order.ip_address = request.META.get('REMOTE_ADDR')
order.user = None
if request.user.is_authenticated():
order.user = request.user
order.status = Order.SUBMITTED
order.save()
if order.pk:
cart_items = cart.get_cart_items(request)
for ci in cart_items:
oi = OrderItem()
oi.order = order
oi.quantity = ci.quantity
oi.price = ci.price
oi.product = ci.product
oi.save()
cart.empty_cart(request)
if request.user.is_authenticated():
from accounts import profile
profile.set(request)
return order
示例2: addOrder
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import user [as 别名]
def addOrder(request):
c = request.POST
tableData = json.loads( c['tableData']);
today = jDateField();
today = today.to_python(datetime.datetime.now())
order = Order(submitDate=today)
status = OrderItem.ORDER_ITEM_STATUS_CHOICES[0][0]
order.user = request.user
isforall = 'isforall' in request.POST and request.POST['isforall']
if request.user.is_superuser:
order.status = 'A'
if isforall:
status = 'P'
order.user = None
order.save()
#print tableData
for order_item in tableData:
#print order_item[2]
if order_item[3] == '':
category = None
else:
category = Category.objects.filter(pk=order_item[3])[0]
orderitem=OrderItem(order=order,
category=category,
quantity=int(order_item[1]),
description = order_item[4],
status= status #if it's admin and the order belongs to the public ..., if it's admin the order is accepted
)
orderitem.save()
if request.user.is_superuser and isforall:
inform_purchase_agent(subject='سفارش نیازمند خرید است',message=render_to_string('mail/buy_orderitem.html',{'orderitem' : orderitem}))
c = {'rlink' : '../../myorders/' , 'success' : "سفارش شما با موفقیت ثبت شد تا لحظاتی دیگر به فهرست سفارشاتتان خواهید رفت"}
if request.user.is_superuser:
if not isforall :
inform_warehouse_manager( message=render_to_string('mail/order_warehouse_manager.html', {'order': order}),
subject='سفارش نیازمند بررسی است')
else:
inform_admin('سفارش جدید', render_to_string('mail/order_added.html', {'order': order}))
return render_to_response("success.html",c);
示例3: create_order
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import user [as 别名]
def create_order(request):
""" function that takes a POST request and adds a product instance to the current customer's shopping cart """
print('create_order!!!!')
post_data = request.POST.copy()
cart_items = cart.get_cart_items(request)
order = Order()
username = request.session['username']
custom_user = Customer.objects.get(
user = User.objects.get(
username = request.session['username']))
order.user = custom_user
order.email = post_data.get('email',1)
order.phone = post_data.get('phone',1)
order.ip_address = request.META.get('REMOTE_ADDR')
order.save()
for cart_item in cart_items:
product = OrderItem()
product.order = order
product.product = cart_item.product
product.quantity = cart_item.quantity
product.save()
cart.empty_cart(request)
print_order(order.id)
return order
示例4: truck_page
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import user [as 别名]
def truck_page(truck):
items = session.query(Item).filter(Item.operator_id == truck)
if request.method == "POST":
user = User()
user.firstName = request.form.get("firstName")
user.lastName = request.form.get("lastName")
user.email = request.form.get("email")
session.add(user)
session.commit()
order = Order()
order.operator_id = truck
order.user = user
order.status = "created"
session.add(order)
session.commit()
for item_id in request.form.getlist("item"):
orderitem = OrderItems()
orderitem.order_id = order.id
orderitem.item_id = item_id
item = items.filter(Item.id == item_id).first()
session.add(orderitem)
session.commit()
return render_template("checkout.html", key=stripe_keys["publishable_key"], order=order, user=user)
else:
items = items.all()
items = filter(lambda x: x.count > 0, items)
return render_template("truckPage.html", items=items)
示例5: create_order
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import user [as 别名]
def create_order(request, transaction_id):
order = Order()
checkout_form = CheckoutForm(request.POST, instance = order)
order = checkout_form.save(commit = False)
order.transaction_id = transaction_id
order.ip_address = request.META.get('REMOTE_ADDR')
if request.user.is_authenticated():
order.user = request.user
order.status = Order.SUBMITTED
order.save()
# if the order save succeeded
if order.pk:
cart_items = shoppingcart.get_cart_items(request)
for ci in cart_items:
# create order item for each cart item
oi = OrderItem()
oi.order = order
oi.quantity = ci.quantity
oi.price = ci.price
oi.product = ci.product
oi.save()
# all set, empty card
shoppingcart.empty_cart(request)
# save profile info for future orders
if request.user.is_authenticated():
from accounts import profile
profile.set(request)
# return the new order object
return order
示例6: ErrorList
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import user [as 别名]
if not request.user.is_authenticated():
form._errors.setdefault("__all__", ErrorList()).append("Для заказа авторизируйтесь.")
else:
try:
rpc_srv = conn.TimeoutServerProxy(office.xmlrpc, timeout=2)
res = rpc_srv.reserve_car(car_id, start_date.strftime("%Y-%m-%d"), end_date.strftime("%Y-%m-%d"))
except Exception, exc:
return render(request, 'message.html', {'result': 'Офис не ответил.' + str(exc)})
if res == False:
form._errors.setdefault("__all__", ErrorList()).append("Невозможно совершить заказ.")
else:
order = Order()
order.reserve(car_id, car['name'], start_date, end_date)
order.office = office
order.order = int(res[0])
order.sum = int(res[1])
order.user = request.user
order.save()
return HttpResponseRedirect(reverse('account:index'))
return render(request, 'catalog/detail.html', {
'car': car,
'form': form,
})
def reserve(request, office_name, car_id):
pass