本文整理汇总了Python中accounts.models.Account.from_obj方法的典型用法代码示例。如果您正苦于以下问题:Python Account.from_obj方法的具体用法?Python Account.from_obj怎么用?Python Account.from_obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.models.Account
的用法示例。
在下文中一共展示了Account.from_obj方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkout
# 需要导入模块: from accounts.models import Account [as 别名]
# 或者: from accounts.models.Account import from_obj [as 别名]
def checkout(request, cart, order):
"""Handle checkout process - if the order is completed, show the success
page, otherwise show the checkout form.
"""
# if the cart is already linked with an order, show that order
if not order and cart.order_obj:
return redirect(cart.order_obj)
if order and order.status >= Order.STATUS_PAID:
if cart.order_obj == order:
cart.clear()
return {
"template": "success",
"order": order,
}
if request.user.is_authenticated():
account = Account.objects.for_user(request.user)
get_user_form = lambda *a: None
else:
account = Account()
get_user_form = partial(CheckoutUserForm)
if order:
get_form = partial(OrderForm, instance=order)
get_gift_form = partial(GiftRecipientForm, prefix='gift',
instance=order.get_gift_recipient())
def sanity_check():
return 0
new_order = False
else:
# set initial data from the user's account, the shipping
# options, and any saved session data
initial = {}
if account.pk and not initial:
initial.update(account.as_dict())
shipping_module = get_shipping_module()
if shipping_module:
initial.update(shipping_module.get_session(request))
initial.update(request.session.get(CHECKOUT_SESSION_KEY, {}))
get_form = partial(OrderForm, initial=initial)
get_gift_form = partial(GiftRecipientForm, prefix='gift')
sanity_check = lambda: cart.subtotal
new_order = True
# Add in any custom cart verification here
cart_errors = []
if request.method == 'POST':
form = get_form(request.POST, sanity_check=sanity_check())
user_form = get_user_form(request.POST)
save_details = not account.pk and request.POST.get('save-details')
if save_details and user_form:
# if creating a new user, the email needs to be unused
form.require_unique_email = True
user_form_valid = user_form.is_valid()
else:
user_form_valid = True
gift_form = get_gift_form(request.POST)
is_gift = request.POST.get('is_gift')
gift_form_valid = gift_form.is_valid() if is_gift else True
if form.is_valid() and (order or not cart.empty()) and \
user_form_valid and gift_form_valid and not len(cart_errors):
# save the order obj to the db...
order = form.save(commit=False)
order.currency = cart.currency
# save details to account if requested
if save_details:
account.from_obj(order)
if user_form:
user = user_form.save(email=order.email, name=order.name)
account.user = user
auth_user = authenticate(
username=user.email,
password=user_form.cleaned_data['password1'])
login(request, auth_user)
account.save()
if account.pk:
order.account = account
order.save()
if is_gift:
recipient = gift_form.save(commit=False)
recipient.order = order
recipient.save()
elif gift_form.instance and gift_form.instance.pk:
gift_form.instance.delete()
# save any cart lines to the order, overwriting existing lines, but
#.........这里部分代码省略.........