No Description

adminver.py 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. # import sqlalchemy as db
  2. #
  3. # # connect to server
  4. # engine = db.create_engine('mysql+pymysql://root:@0.0.0.0/registro_escolar_1')
  5. #
  6. # connection = engine.connect()
  7. #
  8. # ######################################### lo viejo arriba,
  9. ######################################### lo nuevo abajo
  10. from connect import connection
  11. import sqlalchemy as db
  12. #########################################
  13. # esta funcion se obtiene cuando un administrador quiere ver los perfiles de administradores
  14. # url: /admin/ver/admin
  15. def admin():
  16. query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u,administracion a WHERE u.id = a.user_id'
  17. result_db = connection.execute(query).fetchall()
  18. ###### headers
  19. headers = '['
  20. headers += '{"nombre":"Nombre"}'
  21. headers += ','
  22. headers += '{"nombre":"Posicion"}'
  23. headers += ','
  24. headers += '{"nombre":"Email"}'
  25. headers += ','
  26. headers += '{"nombre":"Informacion"}'
  27. headers += ','
  28. headers += '{"nombre":"Editar"}'
  29. headers += ']'
  30. ###### tabla
  31. modal_content = '['
  32. tabla = '['
  33. i = 0
  34. len_result = len(result_db)
  35. for q in result_db:
  36. i = i+1
  37. tabla += '{'
  38. modal_content += '{'
  39. tabla += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
  40. modal_content += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
  41. tabla += ','
  42. modal_content += ','
  43. query = 'SELECT posicion FROM administracion a WHERE a.user_id = ' + str(q[0])
  44. posicion = connection.execute(query).fetchall()
  45. tabla += '"Posicion":"'+(str(posicion[0][0]))+'"'
  46. modal_content += '"Posicion":"'+(str(posicion[0][0]))+'"'
  47. tabla += ','
  48. modal_content += ','
  49. tabla += '"Email":"'+(q[3])+'"'
  50. modal_content += '"Email":"'+(q[3])+'"'
  51. tabla += ','
  52. modal_content += ','
  53. tabla += '"user_id":"'+(str(q[0]))+'"'
  54. modal_content += '"user_id":"'+(str(q[0]))+'"'
  55. tabla += '}'
  56. modal_content += '}'
  57. if i < len_result:
  58. tabla += ','
  59. modal_content += ','
  60. tabla += ']'
  61. modal_content += ']'
  62. ###### info
  63. info = '{'
  64. info += '"dash_name":"Manejar Administracion"'
  65. info += ','
  66. info += '"dash_link":"/admin/ver/"'
  67. info += ','
  68. info += '"dash_sub_name":"Administracion Registrados"'
  69. info += ','
  70. info += '"add":"Anadir Administracion"'
  71. info += ','
  72. info += '"add_link":"/admin/forma/add/administracion/"'
  73. info += ','
  74. info += '"dir1":"#"'
  75. info += ','
  76. info += '"dir2":"/admin/forma/edit/administracion/"'
  77. info += '}'
  78. ###### modal
  79. modal = '{'
  80. modal += '"infoName":"Ver informacion"'
  81. modal += ','
  82. modal += '"editName":"/admin/ver/"'
  83. modal += '}'
  84. result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}'
  85. # print(result)
  86. return(result)
  87. # esta funcion se obtiene cuando un administrador quiere ver los perfiles de encargados
  88. # url: /admin/ver/encargados
  89. def encargados():
  90. query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u,madres m WHERE u.id = m.user_id'
  91. result_db = connection.execute(query).fetchall()
  92. ###### headers
  93. headers = '['
  94. headers += '{"nombre":"Nombre"}'
  95. headers += ','
  96. headers += '{"nombre":"Hijos matriculados"}'
  97. headers += ','
  98. headers += '{"nombre":"Especialidad"}'
  99. headers += ','
  100. headers += '{"nombre":"Informacion"}'
  101. headers += ','
  102. headers += '{"nombre":"Editar"}'
  103. headers += ']'
  104. ###### tabla
  105. tabla = '['
  106. modal_content = '['
  107. i = 0
  108. len_result = len(result_db)
  109. for q in result_db:
  110. i = i+1
  111. tabla += '{'
  112. modal_content += '{'
  113. tabla += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
  114. modal_content += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
  115. tabla += ','
  116. modal_content += ','
  117. query = 'SELECT count(*) FROM madres_estudiantes me WHERE me.madre_id = ' + str(q[0])
  118. total_hijos = connection.execute(query).fetchall()
  119. tabla += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"'
  120. modal_content += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"'
  121. tabla += ','
  122. modal_content += ','
  123. tabla += '"Email":"'+(q[3])+'"'
  124. modal_content += '"Email":"'+(q[3])+'"'
  125. tabla += ','
  126. modal_content += ','
  127. tabla += '"user_id":"'+str(q[0])+'"'
  128. modal_content += '"user_id":"'+str(q[0])+'"'
  129. tabla += '}'
  130. modal_content += '}'
  131. if i < len_result:
  132. tabla += ','
  133. modal_content += ','
  134. tabla += ']'
  135. modal_content += ']'
  136. ###### info
  137. info = '{'
  138. info += '"dash_name":"Manejar Encargados"'
  139. info += ','
  140. info += '"dash_link":"/admin/ver/"'
  141. info += ','
  142. info += '"dash_sub_name":"Encargados Registrados"'
  143. info += ','
  144. info += '"add":"Anadir Encargados"'
  145. info += ','
  146. info += '"add_link":"/admin/forma/add/madre/"'
  147. info += ','
  148. info += '"dir1":"#"'
  149. info += ','
  150. info += '"dir2":"/admin/forma/edit/madre/"'
  151. info += '}'
  152. ###### modal
  153. modal = '{'
  154. modal += '"infoName":"Ver informacion"'
  155. modal += ','
  156. modal += '"editName":"/admin/ver/"'
  157. modal += '}'
  158. result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}'
  159. # print(result)
  160. return(result)
  161. # esta funcion se obtiene cuando un administrador quiere ver los perfiles de enfermeras
  162. # url: /admin/ver/enfermeria
  163. def enfermeria():
  164. query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u,enfermeras e WHERE u.id = e.user_id'
  165. result_db = connection.execute(query).fetchall()
  166. ###### headers
  167. headers = '['
  168. headers += '{"nombre":"Nombre"}'
  169. headers += ','
  170. headers += '{"nombre":"Especialidad"}'
  171. headers += ','
  172. headers += '{"nombre":"Email"}'
  173. headers += ','
  174. headers += '{"nombre":"Informacion"}'
  175. headers += ','
  176. headers += '{"nombre":"Editar"}'
  177. headers += ']'
  178. ###### tabla
  179. tabla = '['
  180. modal_content = '['
  181. i = 0
  182. len_result = len(result_db)
  183. for q in result_db:
  184. i = i+1
  185. tabla += '{'
  186. modal_content += '{'
  187. tabla += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
  188. modal_content += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
  189. tabla += ','
  190. modal_content += ','
  191. query = 'SELECT especialidad FROM enfermeras e WHERE e.user_id = ' + str(q[0])
  192. especialidad = connection.execute(query).fetchall()
  193. tabla += '"Especialidad":"'+(str(especialidad[0][0]))+'"'
  194. modal_content += '"Especialidad":"'+(str(especialidad[0][0]))+'"'
  195. tabla += ','
  196. modal_content += ','
  197. tabla += '"Email":"'+(q[3])+'"'
  198. modal_content += '"Email":"'+(q[3])+'"'
  199. tabla += ','
  200. modal_content += ','
  201. tabla += '"user_id":"'+str(q[0])+'"'
  202. modal_content += '"user_id":"'+str(q[0])+'"'
  203. tabla += '}'
  204. modal_content += '}'
  205. if i < len_result:
  206. tabla += ','
  207. modal_content += ','
  208. tabla += ']'
  209. modal_content += ']'
  210. ###### info
  211. info = '{'
  212. info += '"dash_name":"Manejar Enfermeria"'
  213. info += ','
  214. info += '"dash_link":"/admin/ver/"'
  215. info += ','
  216. info += '"dash_sub_name":"Enfermeras Registrados"'
  217. info += ','
  218. info += '"add":"Anadir Enfermera"'
  219. info += ','
  220. info += '"add_link":"/admin/forma/add/enfermera/"'
  221. info += ','
  222. info += '"dir1":"#"'
  223. info += ','
  224. info += '"dir2":"/admin/forma/edit/enfermera/"'
  225. info += '}'
  226. ###### modal
  227. modal = '{'
  228. modal += '"infoName":"Ver informacion"'
  229. modal += ','
  230. modal += '"editName":"/admin/ver/"'
  231. modal += '}'
  232. result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}'
  233. # print(result)
  234. return(result)
  235. # esta funcion se obtiene cuando un administrador quiere ver los perfiles de estudiantes
  236. # url: /admin/ver/estudiantes
  237. def estudiantes():
  238. query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u, estudiantes m WHERE u.id = m.user_id'
  239. result_db = connection.execute(query).fetchall()
  240. ###### headers
  241. headers = '['
  242. headers += '{"nombre":"Nombre"}'
  243. headers += ','
  244. headers += '{"nombre":"Grado"}'
  245. headers += ','
  246. headers += '{"nombre":"Email"}'
  247. headers += ','
  248. headers += '{"nombre":"Informacion"}'
  249. headers += ','
  250. headers += '{"nombre":"Editar"}'
  251. headers += ']'
  252. # headers = '[{"nombre":"Nombre"},{"nombre":"Posicion"},{"nombre":"Informacion"},{"nombre":"Editar"}]'
  253. ###### tabla
  254. tabla = '['
  255. modal_content = '['
  256. i = 0
  257. len_result = len(result_db)
  258. for q in result_db:
  259. i = i+1
  260. tabla += '{'
  261. modal_content += '{'
  262. tabla += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
  263. modal_content += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
  264. tabla += ','
  265. modal_content += ','
  266. query = 'SELECT grado FROM estudiantes e WHERE e.user_id = ' + str(q[0])
  267. total_hijos = connection.execute(query).fetchall()
  268. tabla += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"'
  269. modal_content += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"'
  270. tabla += ','
  271. modal_content += ','
  272. tabla += '"Email":"'+(q[3])+'"'
  273. modal_content += '"Email":"'+(q[3])+'"'
  274. tabla += ','
  275. modal_content += ','
  276. tabla += '"user_id":"'+str(q[0])+'"'
  277. modal_content += '"user_id":"'+str(q[0])+'"'
  278. tabla += '}'
  279. modal_content += '}'
  280. if i < len_result:
  281. tabla += ','
  282. modal_content += ','
  283. tabla += ']'
  284. modal_content += ']'
  285. ###### info
  286. info = '{'
  287. info += '"dash_name":"Manejar Estudiantes"'
  288. info += ','
  289. info += '"dash_link":"/admin/ver/"'
  290. info += ','
  291. info += '"dash_sub_name":"Estudiantes Registrados"'
  292. info += ','
  293. info += '"add":"Anadir Estudiantes"'
  294. info += ','
  295. info += '"add_link":"/admin/forma/add/estudiante/"'
  296. info += ','
  297. info += '"dir1":"#"'
  298. info += ','
  299. info += '"dir2":"/admin/forma/edit/estudiante/"'
  300. info += '}'
  301. ###### modal
  302. modal = '{'
  303. modal += '"infoName":"Ver informacion"'
  304. modal += ','
  305. modal += '"editName":"/admin/ver/"'
  306. modal += '}'
  307. result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}'
  308. # print(result)
  309. return(result)
  310. # esta funcion se obtiene cuando un administrador quiere ver los perfiles de
  311. # url: /admin/ver/facultad
  312. def facultad():
  313. ###### headers
  314. headers = '['
  315. headers += '{"nombre":"Nombre"}'
  316. headers += ','
  317. headers += '{"nombre":"Especialidad"}'
  318. headers += ','
  319. headers += '{"nombre":"Email"}'
  320. headers += ','
  321. headers += '{"nombre":"Informacion"}'
  322. headers += ','
  323. headers += '{"nombre":"Editar"}'
  324. headers += ']'
  325. # headers = '[{"nombre":"Nombre"},{"nombre":"Posicion"},{"nombre":"Informacion"},{"nombre":"Editar"}]'
  326. ###### tabla
  327. query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u,facultad f WHERE u.id = f.user_id'
  328. result_db = connection.execute(query).fetchall()
  329. tabla = '['
  330. modal_content = '['
  331. i = 0
  332. len_result = len(result_db)
  333. for q in result_db:
  334. i = i+1
  335. tabla += '{'
  336. modal_content += '{'
  337. tabla += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
  338. modal_content += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
  339. tabla += ','
  340. modal_content += ','
  341. query = 'SELECT f.especialidad FROM facultad f WHERE f.user_id =' + str(q[0])
  342. total_hijos = connection.execute(query).fetchall()
  343. tabla += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"'
  344. modal_content += '"Hijos Matriculados":"'+str(total_hijos[0][0])+'"'
  345. tabla += ','
  346. modal_content += ','
  347. tabla += '"Email":"'+(q[3])+'"'
  348. modal_content += '"Email":"'+(q[3])+'"'
  349. tabla += ','
  350. modal_content += ','
  351. tabla += '"user_id":"'+str(q[0])+'"'
  352. modal_content += '"user_id":"'+str(q[0])+'"'
  353. tabla += '}'
  354. modal_content += '}'
  355. if i < len_result:
  356. tabla += ','
  357. modal_content += ','
  358. tabla += ']'
  359. modal_content += ']'
  360. ###### info
  361. info = '{'
  362. info += '"dash_name":"Manejar Facultad"'
  363. info += ','
  364. info += '"dash_link":"/admin/ver/"'
  365. info += ','
  366. info += '"dash_sub_name":"Facultad Registrados"'
  367. info += ','
  368. info += '"add":"Anadir Facultad"'
  369. info += ','
  370. info += '"add_link":"/admin/forma/add/facultad/"'
  371. info += ','
  372. info += '"dir1":"#"'
  373. info += ','
  374. info += '"dir2":"/admin/forma/edit/facultad/"'
  375. info += '}'
  376. ###### modal
  377. modal = '{'
  378. modal += '"infoName":"Ver informacion"'
  379. modal += ','
  380. modal += '"editName":"/admin/ver/"'
  381. modal += '}'
  382. result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}'
  383. # print(result)
  384. return(result)
  385. # esta funcion se obtiene cuando un administrador quiere ver las visitas a la oficina
  386. # url: /admin/ver/visitas_oficina
  387. def visita():
  388. query ='SELECT t1.id, t2.nombres e_nombre, t2.apellidos e_apellido,\
  389. t1.nombres p_nombre, t1.apellidos p_apellido, t1.razon, t1.acciones, t1.fecha\
  390. FROM (SELECT v.id, u.nombres, u.apellidos,v.razon, v.acciones, v.fecha\
  391. FROM visitas_oficina v, usuarios u\
  392. WHERE v.estudiante_id = u.id) t1,\
  393. (SELECT v.id, u.nombres, u.apellidos\
  394. FROM visitas_oficina v, usuarios u\
  395. WHERE v.administradora_id = u.id) t2\
  396. WHERE t1.id=t2.id'
  397. result_db = connection.execute(query).fetchall()
  398. ###### headers
  399. headers = '['
  400. headers += '{"nombre":"Dia y hora"}'
  401. headers += ','
  402. headers += '{"nombre":"Nombre Administrador"}'
  403. headers += ','
  404. headers += '{"nombre":"Nombre Estudiante"}'
  405. headers += ','
  406. headers += '{"nombre":"Informacion"}'
  407. headers += ','
  408. headers += '{"nombre":"Editar"}'
  409. headers += ']'
  410. ###### tabla
  411. modal_content = '['
  412. tabla = '['
  413. i = 0
  414. len_result = len(result_db)
  415. for q in result_db:
  416. i = i+1
  417. tabla += '{'
  418. modal_content += '{'
  419. tabla += '"Dia y hora":"'+str(q[7])+'"'
  420. tabla += ','
  421. tabla += '"Nombre Administrador":"'+(q[1])+' '+(q[2])+'"'
  422. modal_content += '"Nombre Administrador":"'+(q[1])+' '+(q[2])+'"'
  423. tabla += ','
  424. modal_content += ','
  425. tabla += '"Nombre Estudiante":"'+(q[3])+' '+(q[4])+'"'
  426. modal_content += '"Nombre Estudiante":"'+(q[3])+' '+(q[4])+'"'
  427. tabla += ','
  428. modal_content += ','
  429. modal_content += '"Dia y hora":"'+str(q[7])+'"'
  430. modal_content += ','
  431. modal_content += '"Razon":"'+(q[5])+'"'
  432. modal_content += ','
  433. modal_content += '"Explicación":"'+(q[6])+'"'
  434. modal_content += ','
  435. tabla += '"user_id":"'+str(q[0])+'"'
  436. modal_content += '"user_id":"'+str(q[0])+'"'
  437. tabla += '}'
  438. modal_content += '}'
  439. if i < len_result:
  440. tabla += ','
  441. modal_content+= ','
  442. tabla += ']'
  443. modal_content += ']'
  444. ###### info
  445. info = '{'
  446. info += '"dash_name":"Administración- Manejar Visitas"'
  447. info += ','
  448. info += '"dash_link":"/admin/ver/"'
  449. info += ','
  450. info += '"dash_sub_name":"Visitas hechas"'
  451. info += ','
  452. info += '"add":"Anadir Visita"'
  453. info += ','
  454. info += '"add_link":"/admin/forma/add/visitas_oficina/"'
  455. info += ','
  456. info += '"dir1":"#"'
  457. info += ','
  458. info += '"dir2":"/admin/forma/edit/visitas_oficina/"'
  459. info += '}'
  460. ###### modal
  461. modal = '{'
  462. modal += '"infoName":"Ver informacion"'
  463. modal += ','
  464. modal += '"editName":"#"'
  465. modal += '}'
  466. result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}'
  467. # print(result)
  468. return(result)