Нет описания

adminver.py 16KB

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