def on_pesq_aluno(): pesq = PesqAlunos() id = pesq.pesquisar() if id: self.aluno = Alunos.get(Alunos.id == int(id)) if self.aluno: self.ui.edtAluno.setText(self.aluno.nome) else: self.ui.edtAluno.clear()
def on_pesquisar(): pesq = PesqAlunos() id = pesq.pesquisar() if id: self.aluno = Alunos.get(Alunos.id == int(id)) if self.aluno: self.ui.edtId.setText(str(self.aluno.id)) self.ui.edtNome.setText(self.aluno.nome) self.ui.set_mode(True)
def filtrar(self, nome): while self.ui.tableWidget.rowCount() > 0: self.ui.tableWidget.removeRow(0) if nome: rows = Alunos.select().where( pw.fn.Upper(Alunos.nome) % pw.fn.Upper(f'%{nome}%')) else: rows = Alunos.select() for row in rows: rowPosition = self.ui.tableWidget.rowCount() self.ui.tableWidget.insertRow(rowPosition) item = QTableWidgetItem(str(row.id)) item.setFlags(Qt.ItemIsEnabled) self.ui.tableWidget.setItem(rowPosition, 0, item) item = QTableWidgetItem(str(row.nome)) item.setFlags(Qt.ItemIsEnabled) self.ui.tableWidget.setItem(rowPosition, 1, item)
def on_id_editing_finished(): if (not self.ui.edtId.text()): return try: self.aluno = Alunos.get(Alunos.id == int(self.ui.edtId.text())) except: pass if self.aluno: self.ui.edtNome.setText(self.aluno.nome) self.ui.set_mode(True)
def on_salvar(): if not self.ui.edtNome.text(): self.alert("Preencha o nome") return try: if not self.aluno: self.aluno = Alunos.create( nome=str(self.ui.edtNome.text())) else: self.aluno.nome = str(self.ui.edtNome.text()) self.aluno.save() except Exception as e: self.alert(str(e)) return self.ui.set_mode(False) self.ui.edtId.setText(str(self.get_next_id())) self.ui.edtNome.clear() self.aluno = None
def get_next_id(self): mid = Alunos.select(pw.fn.Max(Alunos.id)).scalar() return (mid if mid else 0) + 1