def desmatricular(_handler, curso_id, usuario_id): curso_key = ndb.Key(Curso, int(curso_id)) usuario_key = ndb.Key(Usuario, int(usuario_id)) query = Matricula.query_matricula(curso=curso_key, usuario=usuario_key) matricula_key = query.get(keys_only=True) matricula_key.delete() _handler.redirect(router.to_path(matricula, curso_id))
def matriculas(_write_tmpl, curso_id): # Lista de todos alunos do BD alunos = Aluno.query_alunos_ordenados_asc().fetch() #Construção da chave baseado no id do curso curso_key = ndb.Key(Curso, int(curso_id)) lista_de_matriculas = Matricula.query_matriculas_do_curso(curso_key).fetch() # Filtrando apenas chaves dos alunos matriculados chaves_alunos_matriculados = [m.aluno for m in lista_de_matriculas] #montando lista de alunos matriculados e disponiveis alunos_matriculados = [] alunos_disponiveis = [] for aluno in alunos: if aluno.key in chaves_alunos_matriculados: alunos_matriculados.append(aluno) else: alunos_disponiveis.append(aluno) # buscando curso do BD. Usa memcache (NDB) curso = curso_key.get() #Montagem dos parametros do template values = {'curso': curso, 'matricula_salvar_url': router.to_path(salvar_matricula), 'lista_de_alunos_matriculados': alunos_matriculados, 'lista_de_alunos_disponiveis': alunos_disponiveis} _write_tmpl('templates/matricula.html', values)
def matriculas(_resp,curso_id): #Construção da chave baseado no id do curso curso_key = ndb.Key(Curso, int(curso_id)) lista_de_matriculas = Matricula.query_matriculas_do_curso(curso_key).fetch() # Filtrando apenas chaves dos alunos matriculados chaves_alunos_matriculados = [m.aluno for m in lista_de_matriculas] #Buscando alunos matrículados no BD matriculados=ndb.get_multi(chaves_alunos_matriculados) #Transformando propriedade em dicionario def to_dict(entidade): dct=entidade.to_dict() dct['id']=str(entidade.key.id()) return dct matriculados_dcts=[to_dict(aluno) for aluno in matriculados] js=json.dumps(matriculados_dcts) _resp.write(js)
def matricular_usuario(curso_id, usuario_key): curso_key = ndb.Key(Curso, int(curso_id)) matricula = Matricula(curso=curso_key, usuario=usuario_key) matricula.put() return matricula
def __init__(self, curso_key): super(PesquisarMatriculasDeCursoCmd, self).__init__() self.__query = Matricula.query_matriculas_de_curso(curso_key) self.__future = None