def find_and_assign_anonymous_cart(request, queryset=Cart.objects.all()):
 token = request.get_signed_cookie(Cart.COOKIE_NAME, default=None)
 if (not token):
  return
 cart = get_anonymous_cart_from_token(token=token, cart_queryset=queryset)
 if (cart is None):
  return
 cart.change_user(request.user)
 carts_to_close = Cart.objects.open().filter(user=request.user)
 carts_to_close = carts_to_close.exclude(token=token)
 carts_to_close.update(status=Cart.CANCELED, last_status_change=now())

def find_and_assign_anonymous_cart ( request , queryset = Cart . objects . all ( ) ) : token = request . get_signed_cookie ( Cart . COOKIE_NAME , default = None ) if ( not token ) : return cart = get_anonymous_cart_from_token ( token = token , cart_queryset = queryset ) if ( cart is None ) : return cart . change_user ( request . user ) carts_to_close = Cart . objects . open ( ) . filter ( user = request . user ) carts_to_close = carts_to_close . exclude ( token = token ) carts_to_close . update ( status = Cart . CANCELED , last_status_change = now ( ) )
assign cart from cookie to request user :type request: django .