Beispiel #1
0
def update_import_byuuid_item(import_item):
    from ringo.lib.sql import DBSession
    from ringo.model.user import User

    import_item["uuid"] = DBSession.query(
        User.uuid).filter(User.id == import_item["id"]).scalar()
    return import_item
Beispiel #2
0
def load_user(login):
    """Will return the user with the given login
    name. If no user can be found with the given login "None" will be
    returned.

    :login: Login of the user as string
    :returns: User or None

    """
    return DBSession.query(User).filter_by(login=login).scalar()
Beispiel #3
0
    def test_recursive_import_multiple(self, nested_import_items):
        from ringo.model.user import User, Usergroup, Role
        from ringo.lib.imexport import JSONImporter
        from ringo.lib.sql import DBSession

        group_count = DBSession.query(Usergroup).count()
        role_count = DBSession.query(Role).count()
        imported_items = JSONImporter(User).perform(
            json.dumps(nested_import_items))
        DBSession.flush()

        assert len(imported_items) == 2
        assert all(i[1] == "CREATE" for i in imported_items)
        # plus automatically created and one imported (not updated) groups:
        assert (DBSession.query(Usergroup).count() == group_count +
                len(nested_import_items) + 1)
        # plus imported (not updated) groups:
        assert (DBSession.query(Role).count() == role_count +
                len(nested_import_items[0]["roles"]))
Beispiel #4
0
def nested_import_items(nested_import_item):
    from ringo.lib.sql import DBSession
    from ringo.lib.imexport import JSONExporter
    from ringo.model.user import Usergroup, Role

    import_items = [nested_import_item, copy.deepcopy(nested_import_item)]
    import_items[1]["login"] = "******"

    # update-import relations of second item
    import_items[1]["usergroup"] = json.loads(
        JSONExporter(Usergroup, serialized=False).perform(
            DBSession.query(Usergroup).filter(
                Usergroup.name == 'users').one()))
    import_items[1]["roles"] = json.loads(
        JSONExporter(Role,
                     serialized=False).perform(DBSession.query(Role).all()))

    # Identifiable related object can appear multiple times
    import_items[0]["roles"][0]["uuid"] = str(uuid.uuid4())
    import_items[1]["roles"].append(import_items[0]["roles"][0])

    return import_items
Beispiel #5
0
def load_user(login):
    """Will return the user with the given login
    name. If no user can be found with the given login "None" will be
    returned.

    :login: Login of the user as string
    :returns: User or None

    """
    try:
        return DBSession.query(User).filter_by(login=login).one()
    except NoResultFound:
        return None
Beispiel #6
0
def load_user(login):
    """Will return the user with the given login
    name. If no user can be found with the given login "None" will be
    returned.

    :login: Login of the user as string
    :returns: User or None

    """
    try:
        return DBSession.query(User).filter_by(login=login).one()
    except NoResultFound:
        return None
Beispiel #7
0
def import_model(clazzpath):
    """Will return the clazz defined by modul entry in the database of
    the given model. The clazzpath defines the base clazz which which
    defines the ID of the modul it belongs to.
    The function will first import the clazz and load the related modul
    entry for the model from the database. The we look for the clazzpath
    entry of the modul. If the moduls clazzpath is the same as the model
    clazzpath the return the imported model.
    If the clazzpath differs then import the model defined by the moduls
    clazzpath."""
    from ringo.model.modul import ModulItem
    orig_clazz = dynamic_import(clazzpath)
    # Load entry from the database for the given modul
    mid = orig_clazz._modul_id
    modul = DBSession.query(ModulItem).get(mid)
    if modul.clazzpath == clazzpath:
        return orig_clazz
    else:
        # TODO: Is this code ever reached? (ti) <2014-02-25 23:07>
        return import_model(modul.clazzpath)
Beispiel #8
0
def import_model(clazzpath):
    """Will return the clazz defined by modul entry in the database of
    the given model. The clazzpath defines the base clazz which which
    defines the ID of the modul it belongs to.
    The function will first import the clazz and load the related modul
    entry for the model from the database. The we look for the clazzpath
    entry of the modul. If the moduls clazzpath is the same as the model
    clazzpath the return the imported model.
    If the clazzpath differs then import the model defined by the moduls
    clazzpath."""
    from ringo.model.modul import ModulItem
    orig_clazz = dynamic_import(clazzpath)
    # Load entry from the database for the given modul
    mid = orig_clazz._modul_id
    modul = DBSession.query(ModulItem).filter_by(id=mid).one()
    if modul.clazzpath == clazzpath:
        return orig_clazz
    else:
        # TODO: Is this code ever reached? (ti) <2014-02-25 23:07>
        return import_model(modul.clazzpath)
Beispiel #9
0
def is_login_unique(field, data):
    """Validator function as helper for formbar validators"""
    users = DBSession.query(User).filter_by(login=data[field]).all()
    return len(users) == 0
Beispiel #10
0
def is_login_unique(field, data):
    """Validator function as helper for formbar validators"""
    users = DBSession.query(User).filter_by(login=data[field]).all()
    return len(users) == 0