def instructor_list(cls, request): try: token = jwt.decode(request.tokenint, 'secret') #checa token user = Usuarios.get_by_id( token['user_id']) #obtiene usuario dado el token lista = [] #crea lista lstMessage = InstructorList(code=1) # crea objeto mensaje lstBd = Instructor.query().fetch( ) # recupera de base de datos igual a un select * from blabla for i in lstBd: # recorre lista.append( InstructorUpdate( token='', entityKey=i.entityKey, #empresa_key=user.empresa_key.urlsafe(), name=i.name, lastname=i.lastname, age=i.age, sport=i.sport, urlImage=i.urlImage)) lstMessage.data = lista # la manda al messa message = lstMessage #regresa except jwt.DecodeError: message = ClientList(code=-1, data=[]) #token invalido except jwt.ExpiredSignatureError: message = ClientList(code=-2, data=[]) #token expiro return message
def get(self): self.response.headers.add_header('Access-Control-Allow-Origin', '*') self.response.headers['Content-Type'] = 'application/json' id_user = self.request.get('empresa') objemp = Empresa.query(Empresa.codigo_empresa == id_user).get() strKey = objemp.key.urlsafe() myEmpKey = ndb.Key(urlsafe=strKey) myInstructors = Instructor.query() myList = [] for i in myInstructors: myObj = DemoClass() myObj.id = i.key.urlsafe() myObj.name = i.name myObj.lastname = i.lastname myObj.age = i.age myObj.sport = i.sport myObj.urlImage = i.urlImage myList.append(myObj) json_string = json.dumps(myList, default=MyClass) self.response.write(json_string)