<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def registry(db, term=None):
 """List the organizations available in the registry. The function will return the list of organizations. If term parameter is set, it will only return the information about the organizations which match that term. When the given term does not match with any organization from the registry a 'NotFounError' exception will be raised. :param db: database manager :param term: term to match with organizations names :returns: a list of organizations sorted by their name :raises NotFoundError: raised when the given term is not found on any organization from the registry """

    orgs = []

    with db.connect() as session:
        if term:
            orgs = session.query(Organization).\
                filter(Organization.name.like('%' + term + '%')).\
                order_by(Organization.name).all()

            if not orgs:
                raise NotFoundError(entity=term)
        else:
            orgs = session.query(Organization).\
                order_by(Organization.name).all()

        # Detach objects from the session
        session.expunge_all()

    return orgs