Ei kuvausta

adminadmin.py 2.7KB

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