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
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()
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"]))
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
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
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)
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)
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