Geen omschrijving

adminencargados.py 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # from sqlalchemy import metadata
  2. import sqlalchemy as db
  3. # connect to server
  4. engine = db.create_engine('mysql+pymysql://root:@0.0.0.0/registro_escolar_1')
  5. connection = engine.connect()
  6. # estudiantes = db.Table('estudiantes', metadata, autoload=True, autoload_with=engine)
  7. # usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
  8. def encargados():
  9. query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u,madres m WHERE u.id = m.user_id'
  10. result_db = connection.execute(query).fetchall()
  11. ###### headers
  12. headers = '['
  13. headers += '{"nombre":"Nombre"}'
  14. headers += ','
  15. headers += '{"nombre":"Hijos matriculados"}'
  16. headers += ','
  17. headers += '{"nombre":"Especialidad"}'
  18. headers += ','
  19. headers += '{"nombre":"Informacion"}'
  20. headers += ','
  21. headers += '{"nombre":"Editar"}'
  22. headers += ']'
  23. ###### tabla
  24. tabla = '['
  25. modal_content = '['
  26. i = 0
  27. len_result = len(result_db)
  28. for q in result_db:
  29. i = i+1
  30. tabla += '{'
  31. modal_content += '{'
  32. tabla += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
  33. modal_content += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
  34. tabla += ','
  35. modal_content += ','
  36. query = 'SELECT count(*) FROM madres_estudiantes me WHERE me.madre_id = ' + str(q[0])
  37. total_hijos = connection.execute(query).fetchall()
  38. tabla += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"'
  39. modal_content += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"'
  40. tabla += ','
  41. modal_content += ','
  42. tabla += '"Email":"'+(q[3])+'"'
  43. modal_content += '"Email":"'+(q[3])+'"'
  44. tabla += ','
  45. modal_content += ','
  46. tabla += '"user_id":"'+str(q[0])+'"'
  47. modal_content += '"user_id":"'+str(q[0])+'"'
  48. tabla += '}'
  49. modal_content += '}'
  50. if i < len_result:
  51. tabla += ','
  52. modal_content += ','
  53. tabla += ']'
  54. modal_content += ']'
  55. ###### info
  56. info = '{'
  57. info += '"dash_name":"Manejar Encargados"'
  58. info += ','
  59. info += '"dash_link":"/admin/ver/"'
  60. info += ','
  61. info += '"dash_sub_name":"Encargados Registrados"'
  62. info += ','
  63. info += '"add":"Anadir Encargados"'
  64. info += ','
  65. info += '"add_link":"/admin/forma/add/madre/"'
  66. info += ','
  67. info += '"dir1":"#"'
  68. info += ','
  69. info += '"dir2":"/admin/forma/edit/madre/"'
  70. info += '}'
  71. ###### modal
  72. modal = '{'
  73. modal += '"infoName":"Ver informacion"'
  74. modal += ','
  75. modal += '"editName":"/admin/ver/"'
  76. modal += '}'
  77. result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}'
  78. # print(result)
  79. return(result)