Без опису

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 facultad():
  9. ###### headers
  10. headers = '['
  11. headers += '{"nombre":"Nombre"}'
  12. headers += ','
  13. headers += '{"nombre":"Especialidad"}'
  14. headers += ','
  15. headers += '{"nombre":"Email"}'
  16. headers += ','
  17. headers += '{"nombre":"Informacion"}'
  18. headers += ','
  19. headers += '{"nombre":"Editar"}'
  20. headers += ']'
  21. # headers = '[{"nombre":"Nombre"},{"nombre":"Posicion"},{"nombre":"Informacion"},{"nombre":"Editar"}]'
  22. ###### tabla
  23. query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u,facultad f WHERE u.id = f.user_id'
  24. result_db = connection.execute(query).fetchall()
  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 f.especialidad FROM facultad f WHERE f.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 Facultad"'
  59. info += ','
  60. info += '"dash_link":"/admin/ver/"'
  61. info += ','
  62. info += '"dash_sub_name":"Facultad Registrados"'
  63. info += ','
  64. info += '"add":"Anadir Facultad"'
  65. info += ','
  66. info += '"add_link":"/admin/forma/add/facultad/"'
  67. info += ','
  68. info += '"dir1":"#"'
  69. info += ','
  70. info += '"dir2":"/admin/forma/edit/facultad/"'
  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)