12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- # from sqlalchemy import metadata
- import sqlalchemy as db
-
-
- # connect to server
- engine = db.create_engine('mysql+pymysql://root:@0.0.0.0/registro_escolar_1')
-
- connection = engine.connect()
- # estudiantes = db.Table('estudiantes', metadata, autoload=True, autoload_with=engine)
- # usuarios = db.Table('usuarios', metadata, autoload=True, autoload_with=engine)
-
- def admin():
- query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u,administracion a WHERE u.id = a.user_id'
- result_db = connection.execute(query).fetchall()
-
- ###### headers
-
- headers = '['
- headers += '{"nombre":"Nombre"}'
- headers += ','
- headers += '{"nombre":"Posicion"}'
- headers += ','
- headers += '{"nombre":"Email"}'
- headers += ','
- headers += '{"nombre":"Informacion"}'
- headers += ','
- headers += '{"nombre":"Editar"}'
- headers += ']'
-
- ###### tabla
-
-
- modal_content = '['
- tabla = '['
- i = 0
- len_result = len(result_db)
- for q in result_db:
- i = i+1
- tabla += '{'
- modal_content += '{'
- tabla += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
- modal_content += '"Nombre":"'+(q[1])+' '+(q[2])+'"'
- tabla += ','
- modal_content += ','
-
- query = 'SELECT posicion FROM administracion a WHERE a.user_id = ' + str(q[0])
- posicion = connection.execute(query).fetchall()
-
- tabla += '"Posicion":"'+(str(posicion[0][0]))+'"'
- modal_content += '"Posicion":"'+(str(posicion[0][0]))+'"'
-
- tabla += ','
- modal_content += ','
- tabla += '"Email":"'+(q[3])+'"'
- modal_content += '"Email":"'+(q[3])+'"'
- tabla += ','
- modal_content += ','
- tabla += '"user_id":"'+(str(q[0]))+'"'
- modal_content += '"user_id":"'+(str(q[0]))+'"'
- tabla += '}'
- modal_content += '}'
- if i < len_result:
- tabla += ','
- modal_content += ','
- tabla += ']'
- modal_content += ']'
-
- ###### info
-
- info = '{'
- info += '"dash_name":"Manejar Administracion"'
- info += ','
- info += '"dash_link":"/admin/ver/"'
- info += ','
- info += '"dash_sub_name":"Administracion Registrados"'
- info += ','
- info += '"add":"Anadir Administracion"'
- info += ','
- info += '"add_link":"/admin/forma/add/administracion/"'
- info += ','
- info += '"dir1":"#"'
- info += ','
- info += '"dir2":"/admin/forma/edit/administracion/"'
- info += '}'
-
- ###### modal
-
- modal = '{'
- modal += '"infoName":"Ver informacion"'
- modal += ','
- modal += '"editName":"/admin/ver/"'
- modal += '}'
-
- result = '{"headers":'+headers+',"tabla":'+tabla+',"modal_content":'+modal_content+',"info":'+info+',"modal":'+modal+'}'
-
- # print(result)
- return(result)
|