def validate_shipping_address(view):
"""Decorate a view making it require a valid shipping address.
Expects to be decorated with `@validate_cart`.
If either the shipping address or customer email is empty redirects to the
shipping address step.
"""
@wraps(view)
def func(request, checkout):
if checkout.email is None or checkout.shipping_address is None:
return redirect('checkout:shipping-address')
try:
checkout.shipping_address.full_clean()
except ValidationError:
return redirect('checkout:shipping-address')
return view(request, checkout)
return func
评论列表
文章目录