Introduction
The ESP Website uses a powerful program module system to provide flexible functionality for managing educational programs like MIT Splash. Program modules are Python classes that inherit fromProgramModuleObj and can be dynamically enabled or disabled for each program.
Architecture
Base Classes
All program modules are built on a common foundation defined inesp/esp/program/modules/base.py:
ProgramModuleObj
The base class for all program modules. Key features:- Database Model: Extends Django’s
models.Modelto store module configuration - URL Routing: Automatically routes URLs based on module type and view functions
- View Discovery: Uses decorators (
@main_call,@aux_call) to identify view functions - Permission Checking: Built-in decorators for authentication and deadline enforcement
- Module Lifecycle: Methods for checking completion status and requirements
program: Foreign key to the Programmodule: Foreign key to ProgramModule (module definition)seq: Sequence number for orderingrequired: Whether the module is requiredlink_title: Custom link title override
CoreModule
A marker class for core registration modules that serve as the main entry point for a user type:StudentRegCore- Main student registration pageTeacherRegCore- Main teacher registration pageAdminCore- Program dashboard for administratorsOnsiteCore- Onsite registration landing page
Module Types
Modules are categorized bymodule_type, which determines where they appear:
| Module Type | User Role | URL Pattern | Purpose |
|---|---|---|---|
learn | Students | /learn/<program>/... | Student registration and participation |
teach | Teachers | /teach/<program>/... | Teacher registration and class management |
manage | Admins | /manage/<program>/... | Program administration |
onsite | Onsite Staff | /onsite/<program>/... | Day-of-program operations |
json | Various | /json/<program>/... | API endpoints |
volunteer | Volunteers | /volunteer/<program>/... | Volunteer management |
View Decorators
Modules use decorators to define views and enforce permissions:Call Type Decorators
@main_call: Marks the primary view for a module (only one per module)@aux_call: Marks auxiliary/secondary views
Permission Decorators
@needs_student: Requires student role@needs_teacher: Requires teacher role@needs_admin: Requires admin role@needs_onsite: Requires onsite staff role@needs_student_in_grade: Requires student in correct grade range@usercheck_usetl: Checks role based on module type (tl parameter)
Deadline Decorators
@meets_deadline(extension): Checks if a specific deadline has been met@meets_any_deadline(extensions): Checks if any of multiple deadlines are met@meets_cap: Checks if program capacity allows new registrations
Module Properties
Each module defines its properties via themodule_properties() class method:
Module Lifecycle
Initialization
Modules are initialized for each program through:- Program Creation: When a new program is created, modules can be automatically added
- Manual Addition: Admins can enable modules through the admin interface
- Module Extensions: Some modules auto-create settings models (e.g.,
StudentClassRegModuleInfo)
View Resolution
When a user accesses a URL like/learn/Splash/2024/studentreg:
- The URL pattern identifies the module type (
learn), program (Splash/2024), and view name (studentreg) ProgramModuleObj.findModuleObject()locates the appropriate module- The system checks if the view is a main call or aux call
- For core modules, required modules are enforced before showing the main view
- The view function is called with parameters:
(request, tl, one, two, call_txt, extra, prog)
Completion Tracking
Modules can implementisCompleted() to track whether a user has finished a required step:
User Tracking
Modules can define methods to track different user populations:For Student Modules
For Teacher Modules
For Volunteer Modules
Module Extensions
Some modules use database models to store settings, defined inesp/esp/program/modules/module_ext.py:
StudentClassRegModuleInfo
Controls student class registration behavior:- Capacity enforcement
- Class cap multipliers
- Priority registration
- Button customization
- Visibility settings
ClassRegModuleInfo
Controls teacher class registration:- Co-teaching settings
- Class duration limits
- Class size options
- Resource request settings
Template System
Modules can use templates located in:baseDir() method returns the base template directory for a module:
Common Patterns
Creating a Simple Module
Adding Completion Logic
Adding Required Validation
Next Steps
- Student Modules - Modules for student registration
- Teacher Modules - Modules for teacher registration
- Admin Modules - Modules for program administration
- Onsite Modules - Modules for day-of-program operations