Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__pycache__/
*.pyc
pilates.db
venv/
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Pilates Studio Manager

Sistema simples em Flask para organização de agenda e controle de recebimentos em estúdios de pilates. Funciona em ambiente local usando SQLite.

## Instalação

1. Certifique-se de ter o Python 3 instalado.
2. Opcionalmente crie um ambiente virtual:
```
python3 -m venv venv
source venv/bin/activate
```
3. Instale as dependências:
```
pip install -r requirements.txt
```
4. Inicialize o banco de dados:
```
flask init-db
```
5. Inicie o servidor local:
```
flask run
```

A aplicação estará disponível em `http://localhost:5000`.

## Funcionalidades básicas

- Cadastro de alunos e instrutores.
- Agendamento de aulas.
- Registro de pagamentos.
- Visualização rápida das informações mais importantes em telas simples.
105 changes: 105 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1 +1,106 @@
from flask import Flask, render_template, request, redirect, url_for, flash
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///pilates.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.secret_key = 'change-this-key'

db = SQLAlchemy(app)

class Student(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False)
email = db.Column(db.String(120))

class Instructor(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False)

class ClassSchedule(db.Model):
id = db.Column(db.Integer, primary_key=True)
instructor_id = db.Column(db.Integer, db.ForeignKey('instructor.id'), nullable=False)
student_id = db.Column(db.Integer, db.ForeignKey('student.id'), nullable=False)
start_time = db.Column(db.DateTime, nullable=False)

instructor = db.relationship('Instructor')
student = db.relationship('Student')

class Payment(db.Model):
id = db.Column(db.Integer, primary_key=True)
student_id = db.Column(db.Integer, db.ForeignKey('student.id'), nullable=False)
amount = db.Column(db.Float, nullable=False)
paid_at = db.Column(db.Date, default=datetime.utcnow)

student = db.relationship('Student')

@app.route('/')
def index():
schedules = ClassSchedule.query.order_by(ClassSchedule.start_time).all()
return render_template('index.html', schedules=schedules)

@app.route('/students', methods=['GET', 'POST'])
def students():
if request.method == 'POST':
name = request.form['name']
email = request.form.get('email')
if name:
student = Student(name=name, email=email)
db.session.add(student)
db.session.commit()
flash('Aluno adicionado com sucesso!')
return redirect(url_for('students'))
students = Student.query.all()
return render_template('students.html', students=students)

@app.route('/instructors', methods=['GET', 'POST'])
def instructors():
if request.method == 'POST':
name = request.form['name']
if name:
instructor = Instructor(name=name)
db.session.add(instructor)
db.session.commit()
flash('Instrutor adicionado com sucesso!')
return redirect(url_for('instructors'))
instructors = Instructor.query.all()
return render_template('instructors.html', instructors=instructors)

@app.route('/classes', methods=['GET', 'POST'])
def classes():
students = Student.query.all()
instructors = Instructor.query.all()
if request.method == 'POST':
instructor_id = request.form['instructor_id']
student_id = request.form['student_id']
start_time = datetime.fromisoformat(request.form['start_time'])
schedule = ClassSchedule(instructor_id=instructor_id, student_id=student_id, start_time=start_time)
db.session.add(schedule)
db.session.commit()
flash('Aula agendada com sucesso!')
return redirect(url_for('classes'))
schedules = ClassSchedule.query.order_by(ClassSchedule.start_time).all()
return render_template('classes.html', schedules=schedules, students=students, instructors=instructors)

@app.route('/payments', methods=['GET', 'POST'])
def payments():
students = Student.query.all()
if request.method == 'POST':
student_id = request.form['student_id']
amount = float(request.form['amount'])
payment = Payment(student_id=student_id, amount=amount)
db.session.add(payment)
db.session.commit()
flash('Pagamento registrado com sucesso!')
return redirect(url_for('payments'))
payments = Payment.query.order_by(Payment.paid_at.desc()).all()
return render_template('payments.html', payments=payments, students=students)

@app.cli.command('init-db')
def init_db():
db.create_all()
print('Banco de dados inicializado.')

if __name__ == '__main__':
app.run(debug=True)
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask
Flask-SQLAlchemy
27 changes: 27 additions & 0 deletions templates/classes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!doctype html>
<html lang="pt-BR">
<head><meta charset="utf-8"><title>Agendar Aula</title></head>
<body>
<h1>Agendar Aula</h1>
<form method="post">
<select name="student_id" required>
{% for student in students %}
<option value="{{ student.id }}">{{ student.name }}</option>
{% endfor %}
</select>
<select name="instructor_id" required>
{% for instructor in instructors %}
<option value="{{ instructor.id }}">{{ instructor.name }}</option>
{% endfor %}
</select>
<input type="datetime-local" name="start_time" required>
<button type="submit">Agendar</button>
</form>
<ul>
{% for s in schedules %}
<li>{{ s.start_time }} - {{ s.student.name }} com {{ s.instructor.name }}</li>
{% endfor %}
</ul>
<a href="{{ url_for('index') }}">Voltar</a>
</body>
</html>
23 changes: 23 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!doctype html>
<html lang="pt-BR">
<head>
<meta charset="utf-8">
<title>Pilates Studio</title>
</head>
<body>
<h1>Agenda de Aulas</h1>
<nav>
<a href="{{ url_for('students') }}">Alunos</a> |
<a href="{{ url_for('instructors') }}">Instrutores</a> |
<a href="{{ url_for('classes') }}">Agendar Aula</a> |
<a href="{{ url_for('payments') }}">Pagamentos</a>
</nav>
<ul>
{% for s in schedules %}
<li>{{ s.start_time }} - {{ s.student.name }} com {{ s.instructor.name }}</li>
{% else %}
<li>Nenhuma aula agendada.</li>
{% endfor %}
</ul>
</body>
</html>
17 changes: 17 additions & 0 deletions templates/instructors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="pt-BR">
<head><meta charset="utf-8"><title>Instrutores</title></head>
<body>
<h1>Instrutores</h1>
<form method="post">
<input type="text" name="name" placeholder="Nome" required>
<button type="submit">Adicionar</button>
</form>
<ul>
{% for instructor in instructors %}
<li>{{ instructor.name }}</li>
{% endfor %}
</ul>
<a href="{{ url_for('index') }}">Voltar</a>
</body>
</html>
22 changes: 22 additions & 0 deletions templates/payments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<html lang="pt-BR">
<head><meta charset="utf-8"><title>Pagamentos</title></head>
<body>
<h1>Pagamentos</h1>
<form method="post">
<select name="student_id" required>
{% for student in students %}
<option value="{{ student.id }}">{{ student.name }}</option>
{% endfor %}
</select>
<input type="number" step="0.01" name="amount" placeholder="Valor" required>
<button type="submit">Registrar</button>
</form>
<ul>
{% for p in payments %}
<li>{{ p.paid_at }} - {{ p.student.name }} pagou R$ {{ '%.2f'|format(p.amount) }}</li>
{% endfor %}
</ul>
<a href="{{ url_for('index') }}">Voltar</a>
</body>
</html>
18 changes: 18 additions & 0 deletions templates/students.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html lang="pt-BR">
<head><meta charset="utf-8"><title>Alunos</title></head>
<body>
<h1>Alunos</h1>
<form method="post">
<input type="text" name="name" placeholder="Nome" required>
<input type="email" name="email" placeholder="Email (opcional)">
<button type="submit">Adicionar</button>
</form>
<ul>
{% for student in students %}
<li>{{ student.name }} ({{ student.email or '-' }})</li>
{% endfor %}
</ul>
<a href="{{ url_for('index') }}">Voltar</a>
</body>
</html>