本文整理汇总了Python中models.Order.save方法的典型用法代码示例。如果您正苦于以下问题:Python Order.save方法的具体用法?Python Order.save怎么用?Python Order.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Order
的用法示例。
在下文中一共展示了Order.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkout
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [as 别名]
def checkout(request):
quantityChanged = False
userProfile = UserProfile.objects.get(user=request.user)
if not request.session.get(settings.CART_KEY):
return redirect('/cart')
cart = request.session[settings.CART_KEY]
if not cart:
request.flash['message'] = 'No items in cart to checkout with.'
return redirect('/cart', context_instance=RequestContext(request))
lineItems = line_items_from_cart(request)
for li in lineItems:
li.item = Item.objects.get(pk=li.item_id)
if li.item.onHand < li.quantity:
quantityChanged = True
li.quantity = li.item.onHand
request.flash[li.item.name] = 'Quantity on hand for %s is less than ordered, order changed to the number on hand.' % li.item.name
if quantityChanged:
request = update_cart_with_list_line_item(request, lineItems)
return redirect('/cart', context_instance=RequestContext(request))
order = Order(userProfile=userProfile)
order.save()
for li in lineItems:
li_save = LineItem(order=order,item=li.item, quantity=li.quantity)
li_save.save()
update_item = Item.objects.get(pk=li.item.id)
update_item.onHand -= li.quantity
update_item.save()
request.session[settings.CART_KEY] = None
return render_to_response('checkout.html', {'order': order}, context_instance=RequestContext(request))
示例2: create_order
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [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
示例3: user_page
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [as 别名]
def user_page(request):
''' This will return the page with the generated email and manage user '''
email = request.REQUEST['email']
m = hashlib.md5()
# create a new order and put the requester's email in it
new_order = Order(user_email = email)
generated_id = str(new_order.id)
m.update(generated_id)
generated_email = m.hexdigest() + "@jimini.co"
jimini_order_link = 'jimini.co/orders/' + m.hexdigest()
# update database entry with the generated email and order link
new_order.generated_email = generated_email
new_order.jimini_order_link = jimini_order_link
new_order.save() ## TODO WEBSITE NOT TALKING
print generated_email
print jimini_order_link
return render_to_response('user_page.html', {'generated_email' : generated_email})
示例4: place_order_ajax
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [as 别名]
def place_order_ajax(request):
"""
Create a new order
"""
returnDict = {}
if request.method == 'POST':
try:
#First raise the order as we'll need it for the second part :)
order_dict = json.loads(request.POST['datadict'])
order = Order()
order.supplier = Supplier.objects.filter(id=order_dict['supplier']).get()
if order_dict['account'] == "none":
order.account = None
else:
order.account = SupplierAccount.objects.filter(id=order_dict['account']).get()
order.expected_delivery = datetime.datetime.strptime(order_dict['expected_delivery'], "%m/%d/%Y")
order.date_placed = datetime.datetime.now()
order.save()
returnDict['order'] = order.id
#now add the parts in
parts_list = []
for part in order_dict['parts']:
orderpart = PartsToOrder()
orderpart.order = order
orderpart.part = Part.objects.filter(number=part['part_number']).get()
orderpart.quantity = float(part['quantity'])
orderpart.save()
parts_list.append(orderpart.id)
returnDict['parts_list'] = parts_list
except Exception, e:
print e
returnDict['error'] = e.message
示例5: prepare_payment
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [as 别名]
def prepare_payment(request):
if request.method == 'POST':
form = OrderForm(request.POST)
if form.is_valid():
product = Clothes.objects.get(id=request.POST['product_id'])
order = Order(
buyer_id = request.user.id,
address = form.cleaned_data['address'],
phone = form.cleaned_data['phone'],
email = request.user.email,
amount = product.price,
create_date = datetime.now(),
payment_system = '11'
)
order.save()
order.products.add(product)
order.save()
return HttpResponse(prepare_order('11', order.id, order.amount, order.phone, order.email))
else:
raise Http404
variables = RequestContext(request, {
'form': form,
'product': Clothes.objects.get(id=request.POST['product_id']),
})
return render_to_response(
'prepare_order.html',
variables
)
示例6: create_order
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [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
示例7: test_update
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [as 别名]
def test_update(self):
order = Order(name="Dummy Order")
order.save()
for i in range(2):
item = Item(name="Item %i" % i, sku=str(i) * 13, price=D("9.99"), order=order, status=0)
item.save()
tag = Tag(name="Test", content_object=order)
tag.save()
res = self.client.get("/inlines/1/")
self.assertEqual(res.status_code, 200)
order = Order.objects.get(id=1)
self.assertEquals(2, order.item_set.count())
self.assertEquals("Item 0", order.item_set.all()[0].name)
data = {
"name": u"Dummy Order",
"item_set-TOTAL_FORMS": u"4",
"item_set-INITIAL_FORMS": u"2",
"item_set-MAX_NUM_FORMS": u"",
"item_set-0-name": "Bubble Bath",
"item_set-0-sku": "1234567890123",
"item_set-0-price": D("9.99"),
"item_set-0-status": 0,
"item_set-0-order": 1,
"item_set-0-id": 1,
"item_set-1-name": "Bubble Bath",
"item_set-1-sku": "1234567890123",
"item_set-1-price": D("9.99"),
"item_set-1-status": 0,
"item_set-1-order": 1,
"item_set-1-id": 2,
"item_set-2-name": "Bubble Bath",
"item_set-2-sku": "1234567890123",
"item_set-2-price": D("9.99"),
"item_set-2-status": 0,
"item_set-2-order": 1,
"item_set-3-DELETE": True,
"tests-tag-content_type-object_id-TOTAL_FORMS": 3,
"tests-tag-content_type-object_id-INITIAL_FORMS": 1,
"tests-tag-content_type-object_id-MAX_NUM_FORMS": u"",
"tests-tag-content_type-object_id-0-name": u"Test",
"tests-tag-content_type-object_id-0-id": 1,
"tests-tag-content_type-object_id-0-DELETE": True,
"tests-tag-content_type-object_id-1-name": u"Test 2",
"tests-tag-content_type-object_id-2-name": u"Test 3",
}
res = self.client.post("/inlines/1/", data, follow=True)
self.assertEqual(res.status_code, 200)
order = Order.objects.get(id=1)
self.assertEquals(3, order.item_set.count())
self.assertEquals(2, Tag.objects.count())
self.assertEquals("Bubble Bath", order.item_set.all()[0].name)
示例8: checkout
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [as 别名]
def checkout(request, step=0):
if (request.method == 'POST'):
if request.user.is_authenticated():
now = datetime.datetime.utcnow().replace(tzinfo=utc)
current_user = request.user
current_order = Order(date_time=now, user=current_user)
current_order.save()
for i in range(1, 6):
print(request.POST)
try:
item_quantity = int(
request.POST['item_quantity_' + str(i)])
except:
item_quantity = None
if not item_quantity is None:
item_id = request.POST['item_options_' +
str(i)].split(' ')[1]
print(item_id)
current_sticker = Sticker.objects.get(pk=int(item_id))
print(current_sticker)
order_item = OrderItem(
order=current_order,
sticker=current_sticker,
quantity=item_quantity)
order_item.save()
return redirect('/order/' + str(current_order.id) + '/1')
示例9: create_order
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [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
示例10: test_update
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [as 别名]
def test_update(self):
order = Order(name='Dummy Order')
order.save()
for i in range(2):
item = Item(name='Item %i' % i, sku=str(i) * 13, price=D('9.99'), order=order, status=0)
item.save()
tag = Tag(name='Test', content_object=order)
tag.save()
res = self.client.get('/inlines/1/')
self.assertEqual(res.status_code, 200)
order = Order.objects.get(id=1)
self.assertEquals(2, order.item_set.count())
self.assertEquals('Item 0', order.item_set.all()[0].name)
data = {
'name': u'Dummy Order',
'item_set-TOTAL_FORMS': u'4',
'item_set-INITIAL_FORMS': u'2',
'item_set-MAX_NUM_FORMS': u'',
'item_set-0-name': 'Bubble Bath',
'item_set-0-sku': '1234567890123',
'item_set-0-price': D('9.99'),
'item_set-0-status': 0,
'item_set-0-order': 1,
'item_set-0-id': 1,
'item_set-1-name': 'Bubble Bath',
'item_set-1-sku': '1234567890123',
'item_set-1-price': D('9.99'),
'item_set-1-status': 0,
'item_set-1-order': 1,
'item_set-1-id': 2,
'item_set-2-name': 'Bubble Bath',
'item_set-2-sku': '1234567890123',
'item_set-2-price': D('9.99'),
'item_set-2-status': 0,
'item_set-2-order': 1,
'item_set-3-DELETE': True,
'tests-tag-content_type-object_id-TOTAL_FORMS': 3,
'tests-tag-content_type-object_id-INITIAL_FORMS': 1,
'tests-tag-content_type-object_id-MAX_NUM_FORMS': u'',
'tests-tag-content_type-object_id-0-name': u'Test',
'tests-tag-content_type-object_id-0-id': 1,
'tests-tag-content_type-object_id-0-DELETE': True,
'tests-tag-content_type-object_id-1-name': u'Test 2',
'tests-tag-content_type-object_id-2-name': u'Test 3',
}
res = self.client.post('/inlines/1/', data, follow=True)
self.assertEqual(res.status_code, 200)
order = Order.objects.get(id=1)
self.assertEquals(3, order.item_set.count())
self.assertEquals(2, Tag.objects.count())
self.assertEquals('Bubble Bath', order.item_set.all()[0].name)
示例11: buy
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [as 别名]
def buy(request, **kw):
ret_str = u""
if kw['order'] is None or kw['openId'] is None:
mOrder = request.GET.get(u'order', None)
mOpenId = request.GET.get(u'openId', None)
else:
mOrder = kw['order']
mOpenId = kw['openId']
print mOpenId, " ", mOrder
if (mOrder == '' or mOrder is None or mOpenId == '' or mOpenId is None):
result = JsonUtil.obj2json(Result('error', '非法订单'))
return HttpResponse(result, mimetype="text/html")
mTotal = getTotal(mOrder)
if mTotal == -1:
result = Result('error', '非法订单!请重新购买.')
ret_str += unicode(result.getData(), 'utf-8')
else:
o = Order(openId=mOpenId, order_list=mOrder, total=mTotal)
o.save()
result = Result('success', '点餐成功')
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
ret_str += unicode(result.getData(), 'utf-8') + u',购买时间:' + now + u' 谢谢您的惠顾:-)'
if request is None:
return ret_str
else:
return HttpResponse(result, mimetype="text/html")
示例12: save_order_to_db
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [as 别名]
def save_order_to_db(request, instance):
cart_items = get_cart_items(request)
for cart_item in cart_items:
order = Order(product = cart_item['product'], quantity = cart_item['quantity'], order_details_id = instance)
order.save()
request.session.clear()
示例13: get_queryset
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [as 别名]
def get_queryset(self):
orders = Order.objects.filter(stakeholder=self.request.user)
if orders.count() == 0:
order = Order()
order.stakeholder = self.request.user
order.save()
return Order.objects.filter(stakeholder=self.request.user)
示例14: add
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [as 别名]
def add(request):
data = request.POST.getlist('data')
total = float(data[-1].encode('utf-8'))
price = float(data[-2].encode('utf-8'))
total_price = "%.2f" %(total*price)
o1 = Order(datetime=data[0],office=data[1],subject=data[2],\
school=data[3],grade=data[4],classs=data[5],total=total,price=price,total_price=total_price)
o1.save()
return HttpResponseRedirect('/information/order/')
示例15: test_post
# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import save [as 别名]
def test_post(self):
order = Order(name='Dummy Order')
order.save()
data = {}
data.update(self.management_data)
res = self.client.post('/inlineformset/1/', data, follow=True)
self.assertEqual(res.status_code, 200)
self.assertTrue('formset' in res.context)
self.assertFalse('form' in res.context)