# import sqlalchemy as db # # # connect to server # engine = db.create_engine('mysql+pymysql://root:@0.0.0.0/registro_escolar_1') # # connection = engine.connect() # # ######################################### lo viejo arriba, ######################################### lo nuevo abajo from connect import connection import sqlalchemy as db ######################################### # esta funcion se obtiene cuando un administrador quiere ver los perfiles de administradores # url: /admin/ver/admin def admin(): query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u,administracion a WHERE u.id = a.user_id' result_db = connection.execute(query).fetchall() ###### headers headers = '[' headers += '{"nombre":"Nombre"}' headers += ',' headers += '{"nombre":"Posicion"}' headers += ',' headers += '{"nombre":"Email"}' headers += ',' headers += '{"nombre":"Informacion"}' headers += ',' headers += '{"nombre":"Editar"}' headers += ']' ###### tabla modal_content = '[' tabla = '[' i = 0 len_result = len(result_db) for q in result_db: i = i+1 tabla += '{' modal_content += '{' tabla += '"Nombre":"'+(q[1])+' '+(q[2])+'"' modal_content += '"Nombre":"'+(q[1])+' '+(q[2])+'"' tabla += ',' modal_content += ',' query = 'SELECT posicion FROM administracion a WHERE a.user_id = ' + str(q[0]) posicion = connection.execute(query).fetchall() tabla += '"Posicion":"'+(str(posicion[0][0]))+'"' modal_content += '"Posicion":"'+(str(posicion[0][0]))+'"' tabla += ',' modal_content += ',' tabla += '"Email":"'+(q[3])+'"' modal_content += '"Email":"'+(q[3])+'"' tabla += ',' modal_content += ',' tabla += '"user_id":"'+(str(q[0]))+'"' modal_content += '"user_id":"'+(str(q[0]))+'"' tabla += '}' modal_content += '}' if i < len_result: tabla += ',' modal_content += ',' tabla += ']' modal_content += ']' ###### info info = '{' info += '"dash_name":"Manejar Administracion"' info += ',' info += '"dash_link":"/admin/ver/"' info += ',' info += '"dash_sub_name":"Administracion Registrados"' info += ',' info += '"add":"Anadir Administracion"' info += ',' info += '"add_link":"/admin/forma/add/administracion/"' info += ',' info += '"dir1":"#"' info += ',' info += '"dir2":"/admin/forma/edit/administracion/"' info += '}' ###### modal modal = '{' modal += '"infoName":"Ver informacion"' modal += ',' modal += '"editName":"/admin/ver/"' modal += '}' result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}' # print(result) return(result) # esta funcion se obtiene cuando un administrador quiere ver los perfiles de encargados # url: /admin/ver/encargados def encargados(): query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u,madres m WHERE u.id = m.user_id' result_db = connection.execute(query).fetchall() ###### headers headers = '[' headers += '{"nombre":"Nombre"}' headers += ',' headers += '{"nombre":"Hijos matriculados"}' headers += ',' headers += '{"nombre":"Especialidad"}' headers += ',' headers += '{"nombre":"Informacion"}' headers += ',' headers += '{"nombre":"Editar"}' headers += ']' ###### tabla tabla = '[' modal_content = '[' i = 0 len_result = len(result_db) for q in result_db: i = i+1 tabla += '{' modal_content += '{' tabla += '"Nombre":"'+(q[1])+' '+(q[2])+'"' modal_content += '"Nombre":"'+(q[1])+' '+(q[2])+'"' tabla += ',' modal_content += ',' query = 'SELECT count(*) FROM madres_estudiantes me WHERE me.madre_id = ' + str(q[0]) total_hijos = connection.execute(query).fetchall() tabla += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"' modal_content += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"' tabla += ',' modal_content += ',' tabla += '"Email":"'+(q[3])+'"' modal_content += '"Email":"'+(q[3])+'"' tabla += ',' modal_content += ',' tabla += '"user_id":"'+str(q[0])+'"' modal_content += '"user_id":"'+str(q[0])+'"' tabla += '}' modal_content += '}' if i < len_result: tabla += ',' modal_content += ',' tabla += ']' modal_content += ']' ###### info info = '{' info += '"dash_name":"Manejar Encargados"' info += ',' info += '"dash_link":"/admin/ver/"' info += ',' info += '"dash_sub_name":"Encargados Registrados"' info += ',' info += '"add":"Anadir Encargados"' info += ',' info += '"add_link":"/admin/forma/add/madre/"' info += ',' info += '"dir1":"#"' info += ',' info += '"dir2":"/admin/forma/edit/madre/"' info += '}' ###### modal modal = '{' modal += '"infoName":"Ver informacion"' modal += ',' modal += '"editName":"/admin/ver/"' modal += '}' result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}' # print(result) return(result) # esta funcion se obtiene cuando un administrador quiere ver los perfiles de enfermeras # url: /admin/ver/enfermeria def enfermeria(): query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u,enfermeras e WHERE u.id = e.user_id' result_db = connection.execute(query).fetchall() ###### headers headers = '[' headers += '{"nombre":"Nombre"}' headers += ',' headers += '{"nombre":"Especialidad"}' headers += ',' headers += '{"nombre":"Email"}' headers += ',' headers += '{"nombre":"Informacion"}' headers += ',' headers += '{"nombre":"Editar"}' headers += ']' ###### tabla tabla = '[' modal_content = '[' i = 0 len_result = len(result_db) for q in result_db: i = i+1 tabla += '{' modal_content += '{' tabla += '"Nombre":"'+(q[1])+' '+(q[2])+'"' modal_content += '"Nombre":"'+(q[1])+' '+(q[2])+'"' tabla += ',' modal_content += ',' query = 'SELECT especialidad FROM enfermeras e WHERE e.user_id = ' + str(q[0]) especialidad = connection.execute(query).fetchall() tabla += '"Especialidad":"'+(str(especialidad[0][0]))+'"' modal_content += '"Especialidad":"'+(str(especialidad[0][0]))+'"' tabla += ',' modal_content += ',' tabla += '"Email":"'+(q[3])+'"' modal_content += '"Email":"'+(q[3])+'"' tabla += ',' modal_content += ',' tabla += '"user_id":"'+str(q[0])+'"' modal_content += '"user_id":"'+str(q[0])+'"' tabla += '}' modal_content += '}' if i < len_result: tabla += ',' modal_content += ',' tabla += ']' modal_content += ']' ###### info info = '{' info += '"dash_name":"Manejar Enfermeria"' info += ',' info += '"dash_link":"/admin/ver/"' info += ',' info += '"dash_sub_name":"Enfermeras Registrados"' info += ',' info += '"add":"Anadir Enfermera"' info += ',' info += '"add_link":"/admin/forma/add/enfermera/"' info += ',' info += '"dir1":"#"' info += ',' info += '"dir2":"/admin/forma/edit/enfermera/"' info += '}' ###### modal modal = '{' modal += '"infoName":"Ver informacion"' modal += ',' modal += '"editName":"/admin/ver/"' modal += '}' result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}' # print(result) return(result) # esta funcion se obtiene cuando un administrador quiere ver los perfiles de estudiantes # url: /admin/ver/estudiantes def estudiantes(): query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u, estudiantes m WHERE u.id = m.user_id' result_db = connection.execute(query).fetchall() ###### headers headers = '[' headers += '{"nombre":"Nombre"}' headers += ',' headers += '{"nombre":"Grado"}' headers += ',' headers += '{"nombre":"Email"}' headers += ',' headers += '{"nombre":"Informacion"}' headers += ',' headers += '{"nombre":"Editar"}' headers += ']' # headers = '[{"nombre":"Nombre"},{"nombre":"Posicion"},{"nombre":"Informacion"},{"nombre":"Editar"}]' ###### tabla tabla = '[' modal_content = '[' i = 0 len_result = len(result_db) for q in result_db: i = i+1 tabla += '{' modal_content += '{' tabla += '"Nombre":"'+(q[1])+' '+(q[2])+'"' modal_content += '"Nombre":"'+(q[1])+' '+(q[2])+'"' tabla += ',' modal_content += ',' query = 'SELECT grado FROM estudiantes e WHERE e.user_id = ' + str(q[0]) total_hijos = connection.execute(query).fetchall() tabla += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"' modal_content += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"' tabla += ',' modal_content += ',' tabla += '"Email":"'+(q[3])+'"' modal_content += '"Email":"'+(q[3])+'"' tabla += ',' modal_content += ',' tabla += '"user_id":"'+str(q[0])+'"' modal_content += '"user_id":"'+str(q[0])+'"' tabla += '}' modal_content += '}' if i < len_result: tabla += ',' modal_content += ',' tabla += ']' modal_content += ']' ###### info info = '{' info += '"dash_name":"Manejar Estudiantes"' info += ',' info += '"dash_link":"/admin/ver/"' info += ',' info += '"dash_sub_name":"Estudiantes Registrados"' info += ',' info += '"add":"Anadir Estudiantes"' info += ',' info += '"add_link":"/admin/forma/add/estudiante/"' info += ',' info += '"dir1":"#"' info += ',' info += '"dir2":"/admin/forma/edit/estudiante/"' info += '}' ###### modal modal = '{' modal += '"infoName":"Ver informacion"' modal += ',' modal += '"editName":"/admin/ver/"' modal += '}' result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}' # print(result) return(result) # esta funcion se obtiene cuando un administrador quiere ver los perfiles de # url: /admin/ver/facultad def facultad(): ###### headers headers = '[' headers += '{"nombre":"Nombre"}' headers += ',' headers += '{"nombre":"Especialidad"}' headers += ',' headers += '{"nombre":"Email"}' headers += ',' headers += '{"nombre":"Informacion"}' headers += ',' headers += '{"nombre":"Editar"}' headers += ']' # headers = '[{"nombre":"Nombre"},{"nombre":"Posicion"},{"nombre":"Informacion"},{"nombre":"Editar"}]' ###### tabla query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u,facultad f WHERE u.id = f.user_id' result_db = connection.execute(query).fetchall() tabla = '[' modal_content = '[' i = 0 len_result = len(result_db) for q in result_db: i = i+1 tabla += '{' modal_content += '{' tabla += '"Nombre":"'+(q[1])+' '+(q[2])+'"' modal_content += '"Nombre":"'+(q[1])+' '+(q[2])+'"' tabla += ',' modal_content += ',' query = 'SELECT f.especialidad FROM facultad f WHERE f.user_id =' + str(q[0]) total_hijos = connection.execute(query).fetchall() tabla += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"' modal_content += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"' tabla += ',' modal_content += ',' tabla += '"Email":"'+(q[3])+'"' modal_content += '"Email":"'+(q[3])+'"' tabla += ',' modal_content += ',' tabla += '"user_id":"'+str(q[0])+'"' modal_content += '"user_id":"'+str(q[0])+'"' tabla += '}' modal_content += '}' if i < len_result: tabla += ',' modal_content += ',' tabla += ']' modal_content += ']' ###### info info = '{' info += '"dash_name":"Manejar Facultad"' info += ',' info += '"dash_link":"/admin/ver/"' info += ',' info += '"dash_sub_name":"Facultad Registrados"' info += ',' info += '"add":"Anadir Facultad"' info += ',' info += '"add_link":"/admin/forma/add/facultad/"' info += ',' info += '"dir1":"#"' info += ',' info += '"dir2":"/admin/forma/edit/facultad/"' info += '}' ###### modal modal = '{' modal += '"infoName":"Ver informacion"' modal += ',' modal += '"editName":"/admin/ver/"' modal += '}' result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}' # print(result) return(result) # esta funcion se obtiene cuando un administrador quiere ver las visitas a la oficina # url: /admin/ver/visitas_oficina def visita(): query ='SELECT t1.id, t2.nombres e_nombre, t2.apellidos e_apellido,\ t1.nombres p_nombre, t1.apellidos p_apellido, t1.razon, t1.acciones, t1.fecha\ FROM (SELECT v.id, u.nombres, u.apellidos,v.razon, v.acciones, v.fecha\ FROM visitas_oficina v, usuarios u\ WHERE v.estudiante_id = u.id) t1,\ (SELECT v.id, u.nombres, u.apellidos\ FROM visitas_oficina v, usuarios u\ WHERE v.administradora_id = u.id) t2\ WHERE t1.id=t2.id' result_db = connection.execute(query).fetchall() ###### headers headers = '[' headers += '{"nombre":"Dia y hora"}' headers += ',' headers += '{"nombre":"Nombre Administrador"}' headers += ',' headers += '{"nombre":"Nombre Estudiante"}' headers += ',' headers += '{"nombre":"Informacion"}' headers += ',' headers += '{"nombre":"Editar"}' headers += ']' ###### tabla modal_content = '[' tabla = '[' i = 0 len_result = len(result_db) for q in result_db: i = i+1 tabla += '{' modal_content += '{' tabla += '"Dia y hora":"'+str(q[7])+'"' tabla += ',' tabla += '"Nombre Administrador":"'+(q[1])+' '+(q[2])+'"' modal_content += '"Nombre Administrador":"'+(q[1])+' '+(q[2])+'"' tabla += ',' modal_content += ',' tabla += '"Nombre Estudiante":"'+(q[3])+' '+(q[4])+'"' modal_content += '"Nombre Estudiante":"'+(q[3])+' '+(q[4])+'"' tabla += ',' modal_content += ',' modal_content += '"Dia y hora":"'+str(q[7])+'"' modal_content += ',' modal_content += '"Razon":"'+(q[5])+'"' modal_content += ',' modal_content += '"Explicación":"'+(q[6])+'"' modal_content += ',' tabla += '"user_id":"'+str(q[0])+'"' modal_content += '"user_id":"'+str(q[0])+'"' tabla += '}' modal_content += '}' if i < len_result: tabla += ',' modal_content+= ',' tabla += ']' modal_content += ']' ###### info info = '{' info += '"dash_name":"Administración- Manejar Visitas"' info += ',' info += '"dash_link":"/admin/ver/"' info += ',' info += '"dash_sub_name":"Visitas hechas"' info += ',' info += '"add":"Anadir Visita"' info += ',' info += '"add_link":"/admin/forma/add/visitas_oficina/"' info += ',' info += '"dir1":"#"' info += ',' info += '"dir2":"/admin/forma/edit/visitas_oficina/"' info += '}' ###### modal modal = '{' modal += '"infoName":"Ver informacion"' modal += ',' modal += '"editName":"#"' modal += '}' result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}' # print(result) return(result)