123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- # coding=utf-8
- # from sqlalchemy import metadata
- import sqlalchemy as db
-
- #########################
- # stack overflow:
- # Python sanitizing html from a string
- def escape(htmlstring):
- escapes = {'\"': '"',
- '\'': ''',
- '<': '<',
- '>': '>'}
- # This is done first to prevent escaping other escapes.
- htmlstring = htmlstring.replace('&', '&')
- for seq, esc in escapes.iteritems():
- htmlstring = htmlstring.replace(seq, esc)
- return htmlstring
- #########################
-
- # 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)
-
- def visitas():
- 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_enfermeria v, usuarios u\
- WHERE v.estudiante_id = u.id) t1,\
- (SELECT v.id, u.nombres, u.apellidos\
- FROM visitas_enfermeria v, usuarios u\
- WHERE v.enfermera_id = u.id) t2\
- WHERE t1.id=t2.id'
- result_db = connection.execute(query).fetchall()
-
- ###### headers
-
- headers = '['
- headers += '{"nombre":"Nombre Enfermera"}'
- 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 Enfermera":"'+escape(q[1])+' '+escape(q[2])+'"'
- modal_content += '"Nombre Enfermera":"'+escape(q[1])+' '+escape(q[2])+'"'
- tabla += ','
- modal_content += ','
- tabla += '"Nombre Estudiante":"'+escape(q[3])+' '+escape(q[4])+'"'
- modal_content += '"Nombre Estudiante":"'+escape(q[3])+' '+escape(q[4])+'"'
- tabla += ','
- modal_content += ','
-
- tabla += '"Razon":"'+escape(q[5])+'"'
- modal_content += '"Razon":"'+escape(q[5])+'"'
- modal_content += ','
- modal_content += '"Explicación":"'+escape(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":"Manejar Encargados"'
- info += ','
- info += '"dash_link":"/admin/ver/"'
- info += ','
- info += '"dash_sub_name":"Encargados Registrados"'
- info += ','
- info += '"add":"Anadir Encargados"'
- info += ','
- info += '"add_link":"/enfermera/forma/add/visita/"'
- info += ','
- info += '"dir1":"#"'
- info += ','
- info += '"dir2":"/enfermera/forma/edit/visita/"'
- 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)
|