diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f4c6a14 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +__pycache__/ +*.pyc +pilates.db +venv/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..27e8574 --- /dev/null +++ b/README.md @@ -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. diff --git a/main.py b/main.py index 8b13789..4ffe395 100644 --- a/main.py +++ b/main.py @@ -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) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..fb675a9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask +Flask-SQLAlchemy diff --git a/templates/classes.html b/templates/classes.html new file mode 100644 index 0000000..f0e9dc7 --- /dev/null +++ b/templates/classes.html @@ -0,0 +1,27 @@ + + +