123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562 |
- # coding=utf-8
- # from sqlalchemy import metadata
- import sqlalchemy as db
-
- # connect to server
- engine = db.create_engine('mysql+pymysql://root:@0.0.0.0/registro_escolar_1')
-
- connection = engine.connect()
- # estudiantes = db.Table('estudiantes', metadata, autoload=True, autoload_with=engine)
- # usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
-
-
- # 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\
- FROM (SELECT v.id, u.nombres, u.apellidos,v.razon, v.acciones\
- 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":"Nombre Administrador"}'
- headers += ','
- headers += '{"nombre":"Nombre Estudiante"}'
- headers += ','
- headers += '{"nombre":"Razon"}'
- 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 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 += ','
-
- tabla += '"Razon":"'+(q[5])+'"'
- modal_content += '"Razon":"'+(q[5])+'"'
- modal_content += ','
- modal_content += '"Explicación":"'+(q[6])+'"'
-
-
- 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":"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)
|