Brak opisu

adminestudiantes.py 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 estudiantes():
  9. query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u, estudiantes 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":"Grado"}'
  16. headers += ','
  17. headers += '{"nombre":"Email"}'
  18. headers += ','
  19. headers += '{"nombre":"Informacion"}'
  20. headers += ','
  21. headers += '{"nombre":"Editar"}'
  22. headers += ']'
  23. # headers = '[{"nombre":"Nombre"},{"nombre":"Posicion"},{"nombre":"Informacion"},{"nombre":"Editar"}]'
  24. ###### tabla
  25. tabla = '['
  26. modal_content = '['
  27. i = 0
  28. len_result = len(result_db)
  29. for q in result_db:
  30. i = i+1
  31. tabla += '{'
  32. modal_content += '{'
  33. tabla += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
  34. modal_content += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
  35. tabla += ','
  36. modal_content += ','
  37. query = 'SELECT grado FROM estudiantes e WHERE e.user_id = ' + str(q[0])
  38. total_hijos = connection.execute(query).fetchall()
  39. tabla += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"'
  40. modal_content += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"'
  41. tabla += ','
  42. modal_content += ','
  43. tabla += '"Email":"'+(q[3])+'"'
  44. modal_content += '"Email":"'+(q[3])+'"'
  45. tabla += ','
  46. modal_content += ','
  47. tabla += '"user_id":"'+str(q[0])+'"'
  48. modal_content += '"user_id":"'+str(q[0])+'"'
  49. tabla += '}'
  50. modal_content += '}'
  51. if i < len_result:
  52. tabla += ','
  53. modal_content += ','
  54. tabla += ']'
  55. modal_content += ']'
  56. ###### info
  57. info = '{'
  58. info += '"dash_name":"Manejar Estudiantes"'
  59. info += ','
  60. info += '"dash_link":"/admin/ver/"'
  61. info += ','
  62. info += '"dash_sub_name":"Estudiantes Registrados"'
  63. info += ','
  64. info += '"add":"Anadir Estudiantes"'
  65. info += ','
  66. info += '"add_link":"/admin/forma/add/estudiante/"'
  67. info += ','
  68. info += '"dir1":"#"'
  69. info += ','
  70. info += '"dir2":"/admin/forma/edit/estudiante/"'
  71. info += '}'
  72. ###### modal
  73. modal = '{'
  74. modal += '"infoName":"Ver informacion"'
  75. modal += ','
  76. modal += '"editName":"/admin/ver/"'
  77. modal += '}'
  78. result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}'
  79. # print(result)
  80. return(result)