def obtener_subusuarios_por_lugar_id(self, lid, token=None): pids = [] with open_session() as session: self._obtener_arbol_de_lugares(session, lid, pids) dids = self.silegModel.get_designations_by_places(session, pids) designations = self.silegModel.get_designations(session, dids) users = [ { 'usuario': d.user_id, 'cargo': d.function_id } for d in designations ] return users
def insert_model_data(): """ Se generan los datos para inicializar la base de datos. """ from sileg_model.model import open_session from sileg_model.model.entities.Function import Function, FunctionTypes from sileg_model.model.entities.Place import Place, PlaceTypes def _authority_functions(): functions = ['Decano', 'Vicedecano', 'Secretario', 'Prosecretario'] dedications = ['Exclusiva', 'Simple', 'Tiempo Completo', 'A-H'] caracters = ['Interino', 'Ad-Honorem'] rf = [] for f in functions: for d in dedications: for c in caracters: rf.append(f'{f} - {d} - {c}') return rf def _teacher_functions(): functions = ['Titular', 'Adjunto', 'Asociado', 'Ayudante Alumno', 'Ayudante Diplomado', 'Jefe de Auxiliares Docentes', 'Jefe de Trabajos Prácticos'] dedications = ['Exclusiva', 'Semi Dedicación', 'Semi Exclusiva', 'Simple', 'Tiempo Completo', 'A-H'] caracters = ['Ad-Honorem', 'Interino', 'Ordinario', 'Suplente'] rf = [] for f in functions: for d in dedications: for c in caracters: rf.append(f'{f} - {d} - {c}') extra = ['Consulto', 'Emérito', 'Visitante'] for f in functions: for e in extra: rf.append(f'{f} - {e}') return rf def _insert_functions(session): for f in _authority_functions(): if session.query(Function.id).filter(Function.name == f).count() <= 0: ff = Function() ff.name = f ff.type = FunctionTypes.AUTORIDAD session.add(ff) for f in _teacher_functions(): if session.query(Function.id).filter(Function.name == f).count() <= 0: ff = Function() ff.name = f ff.type = FunctionTypes.DOCENTE session.add(ff) def _get_places(): return [] def _insert_places(session): for p in _get_places(): if session.query(Place.id).filter(Place.name == p).count() <= 0: pp = Place() pp.type = PlaceTypes.DIRECCION pp.name = p session.add(pp) with open_session() as ss: _insert_functions(ss) #_insert_places(ss) ss.commit()
import psycopg2 from sileg_model.model.entities.Designation import Designation, DesignationTypes from sileg_model.model.entities.LeaveLicense import PersonalLeaveLicense, DesignationLeaveLicense from sileg_model.model.entities.Function import FunctionTypes, Function from sileg_model.model import open_session from sileg_model.model.SilegModel import SilegModel from users.model import open_session as open_users_session from users.model.UsersModel import UsersModel if __name__ == '__main__': raise Exception('no funciona por las relaciones!!') try: silegModel = SilegModel() with open_session(echo=False) as session: try: session.query(PersonalLeaveLicense).filter( PersonalLeaveLicense.license_id is not None).delete() session.commit() session.query(PersonalLeaveLicense).delete() session.commit() session.query(DesignationLeaveLicense).filter( DesignationLeaveLicense.license_id is not None).delete() session.commit() session.query(DesignationLeaveLicense).delete() session.commit() fids = [ f.id for f in session.query(Function.id).filter(
import sys import psycopg2 import uuid import json import logging from sileg_model.model import open_session from sileg_model.model.SilegModel import SilegModel from sileg_model.model.entities.Place import PlaceTypes, Place from sileg_model.model.entities.Designation import Designation if __name__ == '__main__': with open_session() as session: ds = [d for d in session.query(Designation).filter(Designation.designation_id == None, Designation.user_id == None).all()] total = len(ds) actual = 0 for d in ds: actual = actual + 1 print(f"{actual}/{total}") session.delete(d) session.commit()
def obtener_lugar_por_id(self, lid, token=None): with open_session() as session: places = self.silegModel.get_places(session, [lid]) if len(places) <= 0: return None return map_place_from_model(places[0])
def obtener_sublugares_por_lugar_id(self, lid, token=None): lids = [] with open_session() as session: self._obtener_arbol_de_lugares(session, lid, lids) return lids