当前位置: 首页>>代码示例>>Python>>正文


Python Order.recipient_name方法代码示例

本文整理汇总了Python中models.Order.recipient_name方法的典型用法代码示例。如果您正苦于以下问题:Python Order.recipient_name方法的具体用法?Python Order.recipient_name怎么用?Python Order.recipient_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Order的用法示例。


在下文中一共展示了Order.recipient_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: choose_recipient

# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import recipient_name [as 别名]
def choose_recipient(request, origami_id, order_id=None):
	'''This returns a form where the user picks a recipient
	and provides shipping information.'''
	origami = Origami.objects.get(id=origami_id)
	
	amazonOrderReferenceId = None
	if request.GET.has_key("session"): amazonOrderReferenceId = str(request.GET["session"])
	
	# if the user backtracked and already has an order_id...
	if order_id != None:
		order = Order.objects.get(id=order_id)
		amazonOrderReferenceId = order.amazonOrderReferenceId
		
		# if the user went back and chose a different origami, update the origami_id
		if order.origami_id != origami_id:
			order.origami_id = origami_id
			order.save()


	# if the user fills out the form and clicks "save and continue"
	if request.method == "POST":
		form = RecipientShippingForm(request.POST) # A form bound to the POST data
		if form.is_valid():
			recipient_name = form.cleaned_data['recipient_name']
			sender_name = form.cleaned_data['sender_name']
			message = form.cleaned_data['message']
			ship_to_name = ""
			ship_to_address = ""
			city = ""
			state = ""
			zip_code = ""
			
			# If the user is submitting the form for the first time, add the data to the db
			if order_id == None:
				order = Order(amazonOrderReferenceId=amazonOrderReferenceId, origami_id=origami_id, order_status='pre-payment', email_code=gen_email_code(), 
						  recipient_name=recipient_name, sender_name=sender_name, message=message, ship_to_name=ship_to_name, 
						  ship_to_address=ship_to_address, city=city, state=state, zip_code=zip_code)
				order.save()

			# otherwise update the data in the db
			else:
				order.recipient_name = recipient_name
				order.sender_name = sender_name
				order.message = message
				order.save()

			params = {}
			params["OrderReferenceAttributes.OrderTotal.Amount"] = str(origami.price)
			params["OrderReferenceAttributes.OrderTotal.CurrencyCode"] = "USD"
			params["OrderReferenceAttributes.SellerNote"] = message
			params["OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId"] = str(order.id)
			
			data = dict(Action='SetOrderReferenceDetails',
							SellerId=MWS_SELLER_ID,
							AmazonOrderReferenceId=str(amazonOrderReferenceId))
							
			data.update(params)
		
			mwsResponse = mws.make_request(data)
			
			pp = pprint.PrettyPrinter(depth=6)
			pp.pprint(mwsResponse.parsed)
			
			order.city = mwsResponse.parsed.OrderReferenceDetails.Destination.PhysicalDestination.City
			order.state = mwsResponse.parsed.OrderReferenceDetails.Destination.PhysicalDestination.StateOrRegion
			order.zip_code = mwsResponse.parsed.OrderReferenceDetails.Destination.PhysicalDestination.PostalCode
			order.save()
			

			# After submitting the form, send user to the payments page
			return HttpResponseRedirect('/payment.html/%s/%s' % (origami_id, order.id))

	# For a GET request where the user already has an order id, pre-populate the form with his previously filled-in values
	elif order_id != None:
		order = Order.objects.get(id=order_id) 
		data = {'recipient_name': order.recipient_name,
			'sender_name': order.sender_name,
			'message': order.message,
			'ship_to_name': order.ship_to_name,
			'ship_to_address': order.ship_to_address,
			'city': order.city,
			'state': order.state,
			'zip_code': order.zip_code}
		form = RecipientShippingForm(data) #A sort of bounded form - if user wants to edit!

	# User is visiting the page for the first time - show him the empty form
	else:
		form = RecipientShippingForm() # An unbound form

	return render_to_response('choose_recipient.html', {'form':form, 'origami':origami, 'order_id':order_id, 'origami_id':origami_id, 'amazonOrderReferenceId': amazonOrderReferenceId},
					  context_instance=RequestContext(request))
开发者ID:mtbottle,项目名称:jimini,代码行数:93,代码来源:views.py


注:本文中的models.Order.recipient_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。