def recalculate_cart(request):
 from cartridge.shop import checkout
 from cartridge.shop.forms import DiscountForm
 from cartridge.shop.models import Cart
 if (request.session.get(u'cart') != request.cart.pk):
  request.session[u'cart'] = request.cart.pk
 request.cart = Cart.objects.from_request(request)
 discount_code = request.session.get(u'discount_code', u'')
 if discount_code:
  names = (u'free_shipping', u'discount_code', u'discount_total')
  clear_session(request, *names)
  discount_form = DiscountForm(request, {u'discount_code': discount_code})
  if discount_form.is_valid():
   discount_form.set_discount()
 handler = (lambda s: (import_dotted_path(s) if s else (lambda *args: None)))
 billship_handler = handler(settings.SHOP_HANDLER_BILLING_SHIPPING)
 tax_handler = handler(settings.SHOP_HANDLER_TAX)
 try:
  if (request.session[u'order'][u'step'] >= checkout.CHECKOUT_STEP_FIRST):
   billship_handler(request, None)
   tax_handler(request, None)
 except (checkout.CheckoutError, ValueError, KeyError):
  pass

def recalculate_cart ( request ) : from cartridge . shop import checkout from cartridge . shop . forms import DiscountForm from cartridge . shop . models import Cart if ( request . session . get ( u'cart' ) != request . cart . pk ) : request . session [ u'cart' ] = request . cart . pk request . cart = Cart . objects . from_request ( request ) discount_code = request . session . get ( u'discount_code' , u'' ) if discount_code : names = ( u'free_shipping' , u'discount_code' , u'discount_total' ) clear_session ( request , * names ) discount_form = DiscountForm ( request , { u'discount_code' : discount_code } ) if discount_form . is_valid ( ) : discount_form . set_discount ( ) handler = ( lambda s : ( import_dotted_path ( s ) if s else ( lambda * args : None ) ) ) billship_handler = handler ( settings . SHOP_HANDLER_BILLING_SHIPPING ) tax_handler = handler ( settings . SHOP_HANDLER_TAX ) try : if ( request . session [ u'order' ] [ u'step' ] >= checkout . CHECKOUT_STEP_FIRST ) : billship_handler ( request , None ) tax_handler ( request , None ) except ( checkout . CheckoutError , ValueError , KeyError ) : pass
updates an existing discount code .