Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
pequenas correções
Browse files Browse the repository at this point in the history
  • Loading branch information
emersonmello committed Aug 16, 2021
1 parent 3848575 commit 9e68c7f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
16 changes: 13 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'password': 'senha',
'host': '127.0.0.1',
'database': 'agenda',
'port': '3306',
'raise_on_warnings': True
}

Expand Down Expand Up @@ -84,11 +85,10 @@ def listar():
@app.route('/editar/', methods=('GET', 'POST'))
def editar():
if request.method == 'GET':
cid = str(request.args.get('id'))
cid = int(request.args.get('id'))
g.db = MySQLConnection(**db_config)
cursor = g.db.cursor(prepared=True)
consulta = ("SELECT nome, email FROM Contato WHERE cID = %s")
cursor.execute(consulta, (cid))
cursor.execute("SELECT nome, email FROM Contato WHERE cId = ?", (cid,))
linha = cursor.fetchone()
cursor.close()
g.db.close()
Expand All @@ -113,6 +113,16 @@ def editar():

return redirect(url_for('listar'))

@app.route('/excluir')
def excluir():
cid = int(request.args.get('id'))
g.db = MySQLConnection(**db_config)
cursor = g.db.cursor(prepared=True)
cursor.execute("DELETE FROM Contato WHERE cId = ?", (cid,))
g.db.commit()
cursor.close()
g.db.close()
return redirect(url_for('listar'))


if __name__ == '__main__':
Expand Down
3 changes: 3 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
{% endif %}
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">

<!-- Font Awesome Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

Expand Down
4 changes: 2 additions & 2 deletions templates/editar.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ <h1>Editar contato</h1>
<form action="{{ url_for('editar') }}" method=post>
<div class="form-group">
<label for="nome">Nome</label>
<input type="text" class="form-control" id="nome" value="{{ contato[0] }}" placeholder="Nome completo">
<input type="text" class="form-control" name="nome" value="{{ contato[0] }}" placeholder="Nome completo">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" value="{{ contato[1] }}" id="email" placeholder="Informe o endereço de email">
<input type="email" class="form-control" value="{{ contato[1] }}" name="email" placeholder="Informe o endereço de email">
</div>
<button type=submit class="btn btn-primary">Atualizar</button>
</form>
Expand Down
4 changes: 2 additions & 2 deletions templates/inserir.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ <h1>Adicionar contato</h1>
<form action="{{ url_for('inserir') }}" method=post>
<div class="form-group">
<label for="nome">Nome</label>
<input type="text" class="form-control" id="nome" placeholder="Nome completo">
<input type="text" class="form-control" name="nome" placeholder="Nome completo">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" placeholder="Informe o endereço de email">
<input type="email" class="form-control" name="email" placeholder="Informe o endereço de email">
</div>
<button type=submit class="btn btn-primary">Adicionar</button>
</form>
Expand Down
2 changes: 2 additions & 0 deletions templates/listar.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h1>Listar contato</h1>
<th>id</th>
<th>Nome</th>
<th>email</th>
<th>Ações</th>
</tr>
</thead>
<tbody>
Expand All @@ -19,6 +20,7 @@ <h1>Listar contato</h1>
<td><a href='/editar?id={{ pessoa.id }}'>{{ pessoa.id }}</a></td>
<td>{{ pessoa.nome }}</td>
<td>{{ pessoa.email }}</td>
<td><a href='/excluir?id={{ pessoa.id }}'><i class="fa fa-trash-o"></i></a></td>
</tr>
{% endfor %}
</tbody>
Expand Down

0 comments on commit 9e68c7f

Please sign in to comment.