Beispiel #1
0
def _buscar_o_crear_usuario_uid(dni):
    with open_users_session() as session:
        uid = UsersModel.get_uid_person_number(session, dni)
        if not uid:
            uid = str(uuid.uuid4())
            user = User()
            user.id = uid
            user.name = 'Importado del sileg.'
            user.lastname = 'Importado del sileg'
            session.add(user)

            idni = IdentityNumber()
            idni.id = str(uuid.uuid4())
            idni.number = dni
            idni.user_id = uid
            session.add(idni)

            session.commit()

    return uid
from login.model import obtener_session
from login.model.LoginModel import LoginModel
from login.model.entities.Login import UserCredentials

f_to_read = sys.argv[1]
with open(f_to_read,'r') as f:
    with open('/var/log/supervisor/importar.log','a') as log:
        log.write(f'Ejecutando importación {datetime.datetime.utcnow()}\n')
        line = f.readline()
        while line:
            lastname, firstname, student_number, username, password, email = line.replace('\n','').split(';')
            dni = username
            try:            
                with open_session() as s:
                    #print(f'Buscando - {firstname} {lastname} {username} {email}')
                    uid = UsersModel.get_uid_person_number(s, dni)
                    #print(uid)
                    if uid:
                        users = UsersModel.get_users(s, [uid])
                        assert len(users) > 0
                        user = users[0]

                        if student_number and student_number != '':
                            # busco legajo y lo agrego en el caso de que no tenga
                            student_numbers = [l for l in user.identity_numbers if l.type == IdentityNumberTypes.STUDENT]
                            if len(student_numbers) < 0:
                                #print(f'Agregando legajo - {firstname} {lastname} {dni} {student_number}')
                                log.write(f'Agregando legajo - {firstname} {lastname} {dni} {student_number}\n')
                                l = IdentityNumber()
                                l.id = str(uuid.uuid4())
                                l.user_id = uid
Beispiel #3
0
                'a': p[1],
                'd': str(p[2]),
                'f': p[3],
                'c': p[4]
            })

    finally:
        cur.close()
finally:
    con.close()

with open_session() as session:
    for p in persons:
        try:
            dni = p['d'].strip()
            user = UsersModel.get_uid_person_number(session, dni)
            if not user:
                uid = str(uuid.uuid4())
                print(f"agregando persona {p['n']} {p['a']} {p['d']}")
                u = User()
                u.id = uid
                u.firstname = p['n']
                u.lastname = p['a']
                u.birthdate = p['f']
                session.add(u)

                i = IdentityNumber()
                i.user_id = uid
                i.number = p['d'].strip()
                i.type = IdentityNumberTypes.DNI
                session.add(i)