Context manager to temporary override the hold policy.

def hold_policy(document, policy, server=False):
    """
    Context manager to temporary override the hold policy.
    """
    old_policy = document._hold
    document._hold = policy
    try:
        yield
    finally:
        if server and not old_policy:
            document.unhold()
        else:
            document._hold = old_policy