This is a comprehensive school management system built with Flask (Python) that handles teacher substitution and absence tracking. The system provides role-based access for administrators and teachers with automated substitution assignment capabilities.
- Backend Framework: Flask (Python 3.11+)
- Database: PostgreSQL with SQLAlchemy ORM
- Authentication: Flask-Login with role-based access control
- Frontend: HTML templates with Bootstrap CSS framework
- Forms: Flask-WTF for form handling and CSRF protection
- Server: Gunicorn WSGI server
/
├── app.py # Main Flask application configuration
├── main.py # Application entry point
├── models.py # Database models (User, Teacher, etc.)
├── forms.py # WTF Forms for user input
├── utils.py # Utility functions
├── config.py # Configuration settings
├── routes/ # Blueprint routes
│ ├── auth_routes.py # Authentication routes
│ ├── admin_routes.py # Admin dashboard routes
│ └── teacher_routes.py # Teacher dashboard routes
├── templates/ # HTML templates
│ ├── base.html # Base template
│ ├── auth/ # Login/authentication templates
│ ├── admin/ # Admin dashboard templates
│ └── teacher/ # Teacher dashboard templates
└── static/ # CSS, JS, and static assets
├── css/
└── js/
- User Registration: Creates user accounts linked to teacher profiles
- Role-Based Access: Two main roles - 'admin' and 'teacher'
- Login System: Separate login flows for admin and teachers
- Session Management: Secure session handling with Flask-Login
- Teacher Management: Add, edit, and manage teacher profiles
- Schedule Management: Create and manage teacher routines/schedules
- Absence Tracking: Record teacher absences and manage substitutions
- Substitution Assignment: Automatically assign substitute teachers based on availability
- Transfer Requests: Handle teacher substitution transfer requests
- Reporting: Generate PDF reports for schedules and substitutions
- Personal Dashboard: View personal schedule and assigned substitutions
- Schedule Viewing: Check weekly routine and class assignments
- Substitution Requests: Request transfers of assigned substitutions
- Absence Reporting: Self-report absences (if enabled)
The system uses 6 main database tables:
- User: Authentication and user accounts
- Teacher: Teacher profile information
- TeacherRoutine: Weekly schedules for teachers
- Absence: Teacher absence records
- Substitution: Substitution assignments
- SubstitutionTransfer: Transfer requests between teachers
When a teacher is absent, the system:
- Identifies all periods the absent teacher was scheduled to teach
- Finds available substitute teachers (those with free periods)
- Assigns substitutions based on availability and workload balance
- Creates substitution records in the database
- Notifies relevant parties
Teachers can request to transfer substitutions to other available teachers:
- Teacher submits transfer request with reason
- Admin reviews and approves/rejects the request
- If approved, substitution is reassigned to the new teacher
- All parties are notified of the change
# main.py starts the application
from app import app
# app.py initializes:
- Flask application
- Database connection
- Authentication system
- Routes registration
- Database table creation- URL Routing: Flask routes requests to appropriate blueprint handlers
- Authentication Check: Flask-Login verifies user authentication
- Role Verification: Routes check user roles for access control
- Form Processing: WTF forms handle user input validation
- Database Operations: SQLAlchemy ORM handles database interactions
- Template Rendering: Jinja2 renders HTML responses
User Input → Forms → Routes → Business Logic → Database → Templates → Response
DATABASE_URL: PostgreSQL database connection stringSESSION_SECRET: Secret key for session encryption
- Connection Pool: 300-second recycle time with pre-ping enabled
- CSRF Protection: Enabled for all forms
- Cascade Deletions: Configured for data integrity
- CSRF Protection: All forms protected against cross-site request forgery
- Password Hashing: Secure password storage using Werkzeug
- Session Security: Secure session management with Flask-Login
- Role-Based Access: Strict access control based on user roles
- Input Validation: Form validation prevents malicious input
python main.py
# Runs on http://0.0.0.0:5000 with debug mode enabledgunicorn --bind 0.0.0.0:5000 --reuse-port --reload main:app
# Uses Gunicorn WSGI server for production deployment- Flexible weekly schedule management
- Support for multiple periods per day
- Free period tracking for substitution availability
- Smart algorithm assigns substitutes based on availability
- Prevents over-assignment and ensures fair distribution
- Handles complex scheduling constraints
- Teachers can request substitution transfers
- Admin approval workflow
- Option to transfer all substitutions for a day
- PDF generation for schedules and reports
- Detailed substitution tracking
- Historical absence data
GET/POST /login- Main login pageGET/POST /admin/login- Admin-specific loginGET/POST /teacher/login- Teacher-specific loginGET /logout- Logout functionality
GET /admin/dashboard- Admin dashboardGET/POST /admin/teachers- Teacher managementGET/POST /admin/schedule- Schedule managementGET/POST /admin/absences- Absence managementGET /admin/substitutions- Substitution overview
GET /teacher/dashboard- Teacher dashboardGET /teacher/schedule- Personal schedule viewGET /teacher/substitutions- Assigned substitutionsPOST /teacher/transfer- Request substitution transfer
The application includes comprehensive error handling:
- Database connection errors
- Form validation errors
- Authentication failures
- Route protection for unauthorized access
- Graceful degradation for missing data
Potential areas for expansion:
- SMS/Email notifications
- Mobile-responsive design improvements
- Advanced reporting and analytics
- Integration with school information systems
- Calendar synchronization
- Automated absence detection