'Mark given library deleted/undeleted based on the flag.'

def delete(self, trans, library, undelete=False):

    if (not trans.user_is_admin()):
        raise exceptions.ItemAccessibilityException('Only    administrators    can    delete    and    undelete    libraries.')
    if undelete:
        library.deleted = False
    else:
        library.deleted = True
    trans.sa_session.add(library)
    trans.sa_session.flush()
    return library
