123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- # from sqlalchemy import metadata
- import sqlalchemy as db
-
-
- import cgi
- #########################
- # stack overflow:
- # Python sanitizing html from a string
- def escape(htmlstring):
- escapes = {'\"': '"',
- '\'': ''',
- '<': '<',
- '>': '>'}
- # This is done first to prevent escaping other escapes.
- htmlstring = htmlstring.replace('&', '&')
- for seq, esc in escapes.iteritems():
- htmlstring = htmlstring.replace(seq, esc)
- return htmlstring
- #########################
-
- # 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 users():
- query = 'SELECT u.id, u.nombres, u.apellidos, u.email FROM usuarios u'
- result_db = connection.execute(query).fetchall()
-
- ###### headers
-
- headers = '['
- headers += '{"nombre":"Nombre"}'
- headers += ','
- headers += '{"nombre":"Email"}'
- headers += ','
- headers += '{"nombre":"Informacion"}'
- headers += ','
- headers += '{"nombre":"Editar"}'
- headers += ']'
- # headers = '[{"nombre":"Nombre"},{"nombre":"Posicion"},{"nombre":"Informacion"},{"nombre":"Editar"}]'
-
- ###### tabla
-
- # <a href="https://www.w3schools.com">Visit W3Schools</a>
-
- # <head><base href="https://www.w3schools.com/images/"></head>
-
- # <link rel="stylesheet" type="text/css" href="theme.css">
-
- tabla = '['
- i = 0
- len_result = len(result_db)
- for q in result_db:
- i = i+1
- tabla += '{'
- name = q[1]+' '+q[2]
- # name = 'aa'
- name = cgi.escape(name)
- tabla += '"Nombre":"'+name+'"'
- tabla += ','
- tabla += '"Email":"'+cgi.escape(q[3])+'"'
- tabla += ','
- tabla += '"user_id":"'+cgi.escape(str(q[0]))+'"'
- tabla += '}'
- if i < len_result:
- tabla += ','
- tabla += ']'
-
- ###### info
-
- info = '{'
- info += '"dash_name":"Manejar test"'
- info += ','
- info += '"dash_link":"/admin/ver/"'
- info += ','
- info += '"dash_sub_name":"user Registrados"'
- info += ','
- info += '"add":"Anadir nada"'
- info += ','
- info += '"add_link":"#"'
- info += ','
- info += '"dir1":"#"'
- info += ','
- info += '"dir2":"#"'
- info += '}'
-
- ###### modal
-
- modal = '{'
- modal += '"infoName":"Ver informacion"'
- modal += ','
- modal += '"editName":"/admin/ver/"'
- modal += '}'
- # modal = '{"yeas":"yes"}'
-
- # # result = '{'+headers+','+tabla+','+info+','+modal+'}'
- # result = '{'
- # result += '"headers":{'+headers+'}'
- # result += ','
- # result += '"tabla":{'+tabla+'}'
- # result += ','
- # result += '"info":'+info
- # result += ','
- # result += '"modal":{'+modal+'}'
- # result += '}'
- result = '{"headers":'+headers+',"tabla":'+tabla+',"info":'+info+',"modal":'+modal+'}'
-
- # print(result)
- return(result)
|