Няма описание

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # coding=utf-8
  2. # from sqlalchemy import metadata
  3. import sqlalchemy as db
  4. #########################
  5. # stack overflow:
  6. # Python sanitizing html from a string
  7. def escape(htmlstring):
  8. escapes = {'\"': '"',
  9. '\'': ''',
  10. '<': '&lt;',
  11. '>': '&gt;'}
  12. # This is done first to prevent escaping other escapes.
  13. htmlstring = htmlstring.replace('&', '&amp;')
  14. for seq, esc in escapes.iteritems():
  15. htmlstring = htmlstring.replace(seq, esc)
  16. return htmlstring
  17. #########################
  18. # connect to server
  19. engine = db.create_engine('mysql+pymysql://root:@0.0.0.0/registro_escolar_1')
  20. connection = engine.connect()
  21. # estudiantes = db.Table('estudiantes', metadata, autoload=True, autoload_with=engine)
  22. # usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
  23. def visitas():
  24. query ='SELECT t1.id, t2.nombres e_nombre, t2.apellidos e_apellido,\
  25. t1.nombres p_nombre, t1.apellidos p_apellido, t1.razon, t1.acciones\
  26. FROM (SELECT v.id, u.nombres, u.apellidos,v.razon, v.acciones\
  27. FROM visitas_enfermeria v, usuarios u\
  28. WHERE v.estudiante_id = u.id) t1,\
  29. (SELECT v.id, u.nombres, u.apellidos\
  30. FROM visitas_enfermeria v, usuarios u\
  31. WHERE v.enfermera_id = u.id) t2\
  32. WHERE t1.id=t2.id'
  33. result_db = connection.execute(query).fetchall()
  34. ###### headers
  35. headers = '['
  36. headers += '{"nombre":"Nombre Enfermera"}'
  37. headers += ','
  38. headers += '{"nombre":"Nombre Estudiante"}'
  39. headers += ','
  40. headers += '{"nombre":"Razon"}'
  41. headers += ','
  42. headers += '{"nombre":"Informacion"}'
  43. headers += ','
  44. headers += '{"nombre":"Editar"}'
  45. headers += ']'
  46. ###### tabla
  47. modal_content = '['
  48. tabla = '['
  49. i = 0
  50. len_result = len(result_db)
  51. for q in result_db:
  52. i = i+1
  53. tabla += '{'
  54. modal_content += '{'
  55. tabla += '"Nombre Enfermera":"'+escape(q[1])+' '+escape(q[2])+'"'
  56. modal_content += '"Nombre Enfermera":"'+escape(q[1])+' '+escape(q[2])+'"'
  57. tabla += ','
  58. modal_content += ','
  59. tabla += '"Nombre Estudiante":"'+escape(q[3])+' '+escape(q[4])+'"'
  60. modal_content += '"Nombre Estudiante":"'+escape(q[3])+' '+escape(q[4])+'"'
  61. tabla += ','
  62. modal_content += ','
  63. tabla += '"Razon":"'+escape(q[5])+'"'
  64. modal_content += '"Razon":"'+escape(q[5])+'"'
  65. modal_content += ','
  66. modal_content += '"Explicación":"'+escape(q[6])+'"'
  67. tabla += ','
  68. modal_content += ','
  69. tabla += '"user_id":"'+str(q[0])+'"'
  70. modal_content += '"user_id":"'+str(q[0])+'"'
  71. tabla += '}'
  72. modal_content += '}'
  73. if i < len_result:
  74. tabla += ','
  75. modal_content+= ','
  76. tabla += ']'
  77. modal_content += ']'
  78. ###### info
  79. info = '{'
  80. info += '"dash_name":"Enfermeria- Manejar Visitas"'
  81. info += ','
  82. info += '"dash_link":"/enfermeria/ver/"'
  83. info += ','
  84. info += '"dash_sub_name":"Visitas hechas"'
  85. info += ','
  86. info += '"add":"Anadir Visita"'
  87. info += ','
  88. info += '"add_link":"/enfermeria/forma/add/visita/"'
  89. info += ','
  90. info += '"dir1":"#"'
  91. info += ','
  92. info += '"dir2":"/enfermeria/forma/edit/visita/"'
  93. info += '}'
  94. ###### modal
  95. modal = '{'
  96. modal += '"infoName":"Ver informacion"'
  97. modal += ','
  98. modal += '"editName":"#"'
  99. modal += '}'
  100. result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}'
  101. # print(result)
  102. return(result)