in app/blueprints/checkout/blueprint.py [0:0]
def display(auth_context):
"""
View function for displaying the checkout page.
Parameters:
auth_context (dict): The authentication context of request.
See middlewares/auth.py for more information.
Output:
Rendered HTML page.
"""
products = []
# Prepares the checkout form.
# See middlewares/form_validation.py for more information.
form = CheckOutForm()
product_id = request.args.get('id')
from_cart = request.args.get('from_cart')
# Checkout one single item if parameter id presents in the URL query string.
# Checkout all the items in the user's cart if parameter from_cart presents
# in the URL query string and parameter id is absent.
if product_id:
product = product_catalog.get_product(product_id)
products.append(product)
elif from_cart:
uid = auth_context.get('uid')
cart = carts.get_cart(uid)
for item in cart:
product = product_catalog.get_product(item.item_id)
products.append(product)
if products:
return render_template('checkout.html',
products=products,
auth_context=auth_context,
form=form,
bucket=product_catalog.BUCKET)
return redirect(url_for('product_catalog_page.display'))