Nova funcão editar e deletar e ccs reformado

parent 90b40f1e
...@@ -85,6 +85,28 @@ def cadastrar(): ...@@ -85,6 +85,28 @@ def cadastrar():
return render_template('cadastrar.html') return render_template('cadastrar.html')
@app.route('/editar/<int:id>', methods=['GET', 'POST'])
def editar(id):
animal = Animal.query.get_or_404(id)
if request.method == 'POST':
try:
animal.nome = request.form['nome']
animal.especie = request.form['especie']
animal.idade = int(request.form['idade'])
animal.peso = float(request.form['peso'])
db.session.commit()
gerar_markdown()
return redirect(url_for('index'))
except Exception as e:
db.session.rollback()
return f"Erro ao editar: {str(e)}"
return render_template('editar.html', animal=animal)
@app.route('/delete/<int:id>') @app.route('/delete/<int:id>')
def delete(id): def delete(id):
animal = Animal.query.get_or_404(id) animal = Animal.query.get_or_404(id)
......
# Relatório de Animais # Relatório de Animais
## Mimosa ## Marcos
- Espécie: Vaca - Espécie: Pitcher
- Idade: 2 anos - Idade: 17 anos
- Peso: 300.0 kg - Peso: 67.0 kg
## Pintadinha
- Espécie: Galinha
- Idade: 4 anos
- Peso: 1.5 kg
html { * {
margin: 0; margin: 0;
padding: 0; padding: 0;
box-sizing: border-box; box-sizing: border-box;
} }
body { body {
font-family: "Lexend", sans-serif; font-family: 'Lexend', sans-serif;
background: linear-gradient(135deg, #f8fafc, #eef2f7); background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #1f2937; min-height: 100vh;
display: flex; padding: 20px;
flex-direction: column;
align-items: center;
padding-top: 100px;
} }
.container {
max-width: 1000px;
margin: 0 auto;
background: white;
border-radius: 12px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
padding: 40px;
}
/* Header */
header {
text-align: center;
margin-bottom: 30px;
}
header h1 {
color: #333;
font-size: 2.5rem;
margin-bottom: 10px;
}
.subtitle {
color: #666;
font-size: 1.1rem;
font-weight: 300;
}
/* Headings */
h1 { h1 {
font-size: 26px; color: #333;
font-size: 2rem;
margin-bottom: 30px;
text-align: center;
}
/* Actions */
.actions {
display: flex;
gap: 10px;
margin-bottom: 30px;
flex-wrap: wrap;
}
/* Buttons */
.btn {
display: inline-block;
padding: 12px 24px;
border-radius: 6px;
text-decoration: none;
font-weight: 600; font-weight: 600;
margin-bottom: 35px; border: none;
color: #111827; cursor: pointer;
letter-spacing: -0.5px; transition: all 0.3s ease;
font-size: 0.95rem;
} }
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
form { .btn-primary:hover {
background: #ffffff; transform: translateY(-2px);
padding: 32px 28px; box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
border-radius: 14px;
width: 340px;
box-shadow: 0 15px 35px rgba(0,0,0,0.08);
border: 1px solid #e5e7eb;
line-height: 2.2;
transition: 0.3s;
} }
.btn-secondary {
background: #f0f0f0;
color: #333;
border: 1px solid #ddd;
}
form:hover { .btn-secondary:hover {
transform: translateY(-3px); background: #e5e5e5;
box-shadow: 0 20px 45px rgba(0,0,0,0.12);
} }
.btn-edit {
background: #3498db;
color: white;
padding: 8px 16px;
font-size: 0.9rem;
}
input { .btn-edit:hover {
width: 100%; background: #2980b9;
padding: 10px 12px; }
margin-top: 6px;
margin-bottom: 14px; .btn-delete {
background: #e74c3c;
color: white;
padding: 8px 16px;
font-size: 0.9rem;
}
.btn-delete:hover {
background: #c0392b;
}
/* Table */
.table-responsive {
overflow-x: auto;
border-radius: 8px; border-radius: 8px;
border: 1px solid #d1d5db; border: 1px solid #eee;
font-size: 14px; }
background: #f9fafb;
transition: all 0.2s ease; .animals-table {
width: 100%;
border-collapse: collapse;
background: white;
}
.animals-table thead {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.animals-table th {
padding: 16px;
text-align: left;
font-weight: 600;
font-size: 1rem;
}
.animals-table td {
padding: 14px 16px;
border-bottom: 1px solid #f0f0f0;
} }
.animals-table tbody tr {
transition: background-color 0.2s ease;
}
input:focus { .animals-table tbody tr:hover {
background-color: #f9f9f9;
}
.animals-table tbody tr:last-child td {
border-bottom: none;
}
.actions-column {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
/* Forms */
.form {
max-width: 600px;
margin: 0 auto;
}
.form-group {
margin-bottom: 20px;
display: flex;
flex-direction: column;
}
.form-group label {
color: #333;
font-weight: 600;
margin-bottom: 8px;
font-size: 1rem;
}
.form-group input {
padding: 12px;
border: 2px solid #ddd;
border-radius: 6px;
font-family: 'Lexend', sans-serif;
font-size: 1rem;
transition: border-color 0.3s ease;
}
.form-group input:focus {
outline: none; outline: none;
border-color: #6b7280; border-color: #667eea;
background: #ffffff; box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
box-shadow: 0 0 0 3px rgba(107,114,128,0.15); }
.form-group input::placeholder {
color: #999;
}
.form-actions {
display: flex;
gap: 12px;
margin-top: 30px;
justify-content: center;
} }
/* Empty State */
.empty-state {
text-align: center;
padding: 60px 20px;
color: #666;
}
.empty-state p {
font-size: 1.2rem;
margin-bottom: 20px;
}
/* Responsive */
@media (max-width: 768px) {
.container {
padding: 20px;
}
header h1 {
font-size: 2rem;
}
button { .actions-column {
flex-direction: column;
}
.btn-edit,
.btn-delete {
width: 100%; width: 100%;
padding: 11px; text-align: center;
border: none; }
border-radius: 8px;
background: #111827; .form-actions {
color: #ffffff; flex-direction: column;
font-size: 14px; }
font-weight: 500;
cursor: pointer; .form-actions .btn {
transition: all 0.25s ease; width: 100%;
text-align: center;
}
.animals-table th,
.animals-table td {
padding: 10px;
font-size: 0.9rem;
}
} }
@media (max-width: 480px) {
body {
padding: 10px;
}
.container {
padding: 15px;
border-radius: 8px;
}
header h1 {
font-size: 1.5rem;
}
.subtitle {
font-size: 0.95rem;
}
.btn {
padding: 10px 16px;
font-size: 0.85rem;
}
button:hover { .animals-table th,
background: #1f2937; .animals-table td {
transform: translateY(-1px); padding: 8px;
box-shadow: 0 6px 15px rgba(0,0,0,0.15); }
} }
...@@ -12,14 +12,35 @@ ...@@ -12,14 +12,35 @@
</head> </head>
<body> <body>
<div class="container">
<h1>Novo Animal</h1> <h1>Novo Animal</h1>
<form method="POST"> <form method="POST" class="form">
Nome: <input type="text" name="nome" required><br> <div class="form-group">
Especie: <input type="text" name="especie" required><br> <label for="nome">Nome:</label>
Idade: <input type="number" name="idade" required><br> <input type="text" id="nome" name="nome" required placeholder="Digite o nome do animal">
Peso: <input type="number" step="any" name="peso" required><br> </div>
<button type="submit">Salvar</button>
<div class="form-group">
<label for="especie">Espécie:</label>
<input type="text" id="especie" name="especie" required placeholder="Ex: Galinha, Vaca, Ovelha">
</div>
<div class="form-group">
<label for="idade">Idade (anos):</label>
<input type="number" id="idade" name="idade" required placeholder="0" min="0">
</div>
<div class="form-group">
<label for="peso">Peso (kg):</label>
<input type="number" id="peso" name="peso" step="0.01" required placeholder="0.00" min="0">
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Salvar</button>
<a href="/" class="btn btn-secondary">Cancelar</a>
</div>
</form> </form>
</div>
</body> </body>
</html> </html>
<!DOCTYPE html>
<html lang="PT-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Lexend:wght@100..900&display=swap" rel="stylesheet">
<title>Editar Animal</title>
</head>
<body>
<div class="container">
<h1>Editar Animal</h1>
<form method="POST" class="form">
<div class="form-group">
<label for="nome">Nome:</label>
<input type="text" id="nome" name="nome" value="{{ animal.nome }}" required>
</div>
<div class="form-group">
<label for="especie">Espécie:</label>
<input type="text" id="especie" name="especie" value="{{ animal.especie }}" required>
</div>
<div class="form-group">
<label for="idade">Idade (anos):</label>
<input type="number" id="idade" name="idade" value="{{ animal.idade }}" required>
</div>
<div class="form-group">
<label for="peso">Peso (kg):</label>
<input type="number" id="peso" name="peso" step="0.01" value="{{ animal.peso }}" required>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Salvar Alterações</button>
<a href="/" class="btn btn-secondary">Cancelar</a>
</div>
</form>
</div>
</body>
</html>
...@@ -12,24 +12,51 @@ ...@@ -12,24 +12,51 @@
</head> </head>
<body> <body>
<h1>Animais Cadastrados</h1> <div class="container">
<a href="/cadastrar"><button>Novo Cadastro</button></a> <header>
<table border="1"> <h1>🐄 Animais da Fazenda</h1>
<p class="subtitle">Gerenciamento de animais cadastrados</p>
</header>
<div class="actions">
<a href="/cadastrar" class="btn btn-primary">➕ Novo Cadastro</a>
</div>
{% if animais %}
<div class="table-responsive">
<table class="animals-table">
<thead>
<tr> <tr>
<th>Nome</th> <th>Nome</th>
<th>Espécie</th> <th>Espécie</th>
<th>Idade</th> <th>Idade</th>
<th>Peso</th> <th>Peso (kg)</th>
<th>Ações</th>
</tr> </tr>
</thead>
<tbody>
{% for a in animais %} {% for a in animais %}
<tr> <tr>
<td>{{ a.nome }}</td> <td><strong>{{ a.nome }}</strong></td>
<td>{{ a.especie }}</td> <td>{{ a.especie }}</td>
<td>{{ a.idade }}</td> <td>{{ a.idade }} anos</td>
<td>{{ a.peso }}</td> <td>{{ a.peso }}</td>
<td class="actions-column">
<a href="/editar/{{ a.id }}" class="btn btn-edit">✏️ Editar</a>
<a href="/delete/{{ a.id }}" class="btn btn-delete" onclick="return confirm('Tem certeza que deseja deletar?')">🗑️ Deletar</a>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody>
</table> </table>
</div>
{% else %}
<div class="empty-state">
<p>Nenhum animal cadastrado ainda.</p>
<a href="/cadastrar" class="btn btn-primary">Cadastre o primeiro animal</a>
</div>
{% endif %}
</div>
</body> </body>
</html> </html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment