本文整理匯總了Python中accounts.models.Account.as_dict方法的典型用法代碼示例。如果您正苦於以下問題:Python Account.as_dict方法的具體用法?Python Account.as_dict怎麽用?Python Account.as_dict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類accounts.models.Account
的用法示例。
在下文中一共展示了Account.as_dict方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: checkout
# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import as_dict [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
#.........這裏部分代碼省略.........