- Split monolithic app.py (400+ lines) into organized modules - Extract models, forms, and commands into separate files - Implement Flask blueprints for route organization - Maintain full functionality with cleaner architecture - Update all templates to use new blueprint URLs - Enhance README with technical documentation Structure: ├── app.py (50 lines) - Flask app factory ├── models.py (62 lines) - SQLAlchemy models ├── forms.py (43 lines) - WTForms definitions ├── commands.py (74 lines) - CLI commands └── routes/ - Blueprint modules for each feature 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
from flask import Flask, render_template
|
|
from models import db, Assessment, Student, ClassGroup
|
|
from commands import init_db
|
|
|
|
# Import blueprints
|
|
from routes.assessments import bp as assessments_bp
|
|
from routes.exercises import bp as exercises_bp
|
|
from routes.grading import bp as grading_bp
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
app.config['SECRET_KEY'] = 'your-secret-key-here'
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///school_management.db'
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
|
|
# Initialize extensions
|
|
db.init_app(app)
|
|
|
|
# Register blueprints
|
|
app.register_blueprint(assessments_bp)
|
|
app.register_blueprint(exercises_bp)
|
|
app.register_blueprint(grading_bp)
|
|
|
|
# Register CLI commands
|
|
app.cli.add_command(init_db)
|
|
|
|
# Main routes
|
|
@app.route('/')
|
|
def index():
|
|
recent_assessments = Assessment.query.order_by(Assessment.date.desc()).limit(5).all()
|
|
total_students = Student.query.count()
|
|
total_assessments = Assessment.query.count()
|
|
total_classes = ClassGroup.query.count()
|
|
return render_template('index.html',
|
|
recent_assessments=recent_assessments,
|
|
total_students=total_students,
|
|
total_assessments=total_assessments,
|
|
total_classes=total_classes)
|
|
|
|
@app.route('/classes')
|
|
def classes():
|
|
classes = ClassGroup.query.order_by(ClassGroup.year, ClassGroup.name).all()
|
|
return render_template('classes.html', classes=classes)
|
|
|
|
@app.route('/students')
|
|
def students():
|
|
students = Student.query.join(ClassGroup).order_by(ClassGroup.name, Student.last_name, Student.first_name).all()
|
|
return render_template('students.html', students=students)
|
|
|
|
return app
|
|
|
|
if __name__ == '__main__':
|
|
app = create_app()
|
|
with app.app_context():
|
|
db.create_all()
|
|
app.run(debug=True) |