def obtener_usuarios_por_search(): try: search = request.args.get('q', None) with open_session() as s: uids = UsersModel.search_user(s, search) usuarios = UsersModel.get_users(s, uids) musers = [map_user_from_model(u) for u in usuarios] return jsonify({'status': 200, 'response': musers}) except Exception as e: return jsonify({'status': 500, 'response': str(e)})
def obtener_usuarios_por_uids(uids=[]): try: with open_session() as s: usuarios = UsersModel.get_users(s, uids) musers = [map_user_from_model(u) for u in usuarios] return jsonify({'status': 200, 'response': musers}) except Exception as e: return jsonify({'status': 500, 'response': str(e)})
def config_dev(binder): """ Configura un ambiente de desarrollo web """ from login.model.LoginModel import LoginModel from users.model.UsersModel import UsersModel from .models.HydraApi import HydraApi from .models.google.GoogleSyncModel import GoogleSyncModel, GoogleSyncModelMock from .models.MailsModel import MailsModel, MailsModelMock binder.bind(LoginModel, LoginModel()) binder.bind(UsersModel, UsersModel()) binder.bind(HydraApi, HydraApi(HydraEnv.HYDRA_ADMIN_URL, HydraEnv.VERIFY_HTTPS)) binder.bind(GoogleSyncModel, GoogleSyncModelMock()) binder.bind(MailsModel, MailsModelMock())
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
import os HYDRA_ADMIN_URL = os.environ.get('HYDRA_ADMIN_URL') VERIFY_HTTPS = bool(int(os.environ.get('VERIFY_HTTPS', 0))) from hydra.model.HydraModel import HydraModel from hydra.model.HydraLocalModel import HydraLocalModel from hydra.model.QRModel import QRModel from login.model.LoginModel import LoginModel from users.model.UsersModel import UsersModel hydraModel = HydraModel(HYDRA_ADMIN_URL, VERIFY_HTTPS) hydraLocalModel = HydraLocalModel() loginModel = LoginModel() usersModel = UsersModel() qrModel = QRModel()
def _obtener_usuarios(self, uids): with open_session() as s: users = UsersModel.get_users(s, uids) musers = [map_user_from_model(u) for u in users] return musers
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
try: cur.execute( 'select pers_nrodoc from empleado e left join persona p on (p.pers_id = e.empleado_pers_id)' ) dnis = [str(d[0]) for d in cur] finally: cur.close() finally: con.close() for dni in dnis: try: print(f'buscando usuario {dni}') with open_users_session() as s2: uid = UsersModel.get_uid_person_number(s2, dni) if not uid: raise Exception(f'no se encuentra uid para el dni {dni}') silegModel = SilegModel() with open_session(echo=False) as session: try: """ elimino fisicamente todas las designaciones de la persona referenciada """ print(f"eliminando designaciones {dni}") for p in session.query(PersonalLeaveLicense.id).filter( PersonalLeaveLicense.user_id == uid).all(): session.query(PersonalLeaveLicense).filter( PersonalLeaveLicense.license_id == p.id).delete() session.commit() session.query(PersonalLeaveLicense).filter( PersonalLeaveLicense.user_id == uid).delete()
'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)