Overview
TheESPUser model extends Django’s built-in User model with ESP-specific functionality for managing students, teachers, volunteers, guardians, and administrators.
Source: esp/esp/users/models/__init__.py
Core Fields
ESPUser inherits from Django’s User model, which provides:Unique username for login
- Max length: 150 characters
- Must be unique
User’s first name
- Max length: 150 characters
User’s last name
- Max length: 150 characters
User’s email address
- Max length: 254 characters
- Used for notifications and password recovery
Django admin panel access
- Default: False
Full Django permissions
- Default: False
User roles/types
- Links to: Django
Groupmodel - Common groups: Student, Teacher, Administrator, Guardian, Educator, Volunteer
User Type Methods
ESP automatically creates membership methods for each user type.Checks if user is a studentReturns: True if user is in the Student groupExample:
Checks if user is a teacher/volunteer instructorReturns: True if user is in the Teacher group
Checks if user has admin privilegesParameters:
program(Program): Check for program-specific admin rights, or global if None
Checks if user is a guardian/parentReturns: True if user is in the Guardian group
Checks if user is a K-12 educatorReturns: True if user is in the Educator group
Checks if user is an onsite volunteerReturns: True if user is in the Volunteer group
Name and Contact Methods
Returns full nameReturns: ” ”Example:
Returns name in last, first formatReturns: ”, ”
Returns properly formatted email address for sending mailReturns:
"Full Name" <[email protected]>Example:Grade and Student Methods
Gets student’s grade levelParameters:
program(Program): Calculate grade for specific program, or current year if None
Gets student’s year of graduationParameters:
program(Program): Use registration profile from program, or latest if None
set_grade(grade)
Sets student’s grade level based on current school yearParameters:
grade(int): Grade level to set
- Calculates graduation year from grade
- Updates StudentInfo record
- Only works for students
set_student_grad_year(grad_year)
Directly sets graduation yearParameters:
grad_year(int): Year of graduation
- Updates StudentInfo.graduation_year
- Only works for students
Teaching Methods
Returns classes taught by this userParameters:
program(Program): Filter by program, or all programs if Noneinclude_rejected(bool): Include rejected classesinclude_cancelled(bool): Include cancelled classes
Returns class sections taught by this userParameters:
program(Program): Filter by programinclude_rejected(bool): Include rejected sectionsinclude_cancelled(bool): Include cancelled sections
Returns all programs where user has taughtReturns: QuerySet of Program objects
Calculates total teaching timeParameters:
program(Program): Filter by programinclude_scheduled(bool): Count already-scheduled classesround_to(float): Round to nearest fraction of hour (0 = no rounding)
Returns time blocks when teacher is availableParameters:
program(Program): Program to check availability forignore_classes(bool): Don’t exclude times they’re teaching
Student Enrollment Methods
Returns classes student is enrolled inParameters:
program(Program): Filter by program, or all if None
Returns class sections student is enrolled inParameters:
program(Program): Filter by program
Returns sections with specified relationship typeParameters:
program(Program): Filter by programverbs(list): Registration types (e.g., [‘Enrolled’, ‘Interested’])
Checks if student is enrolled in specific classParameters:
clsObj(ClassSubject): Class to check
Permission Methods
Checks if user can edit a classParameters:
cls(ClassSubject): Class to check
Checks if user can moderate a sectionParameters:
sec(ClassSection): Section to check
Checks if user can register even when program is fullParameters:
program(Program): Program to check
Checks if user has onsite accessParameters:
program(Program): Check for specific program, or all if None
Role Management
makeRole(role_name)
Adds a role/group to userParameters:
role_name(string): Name of group (e.g., “Teacher”, “Volunteer”)
removeRole(role_name)
Removes a role/group from userParameters:
role_name(string): Name of group to remove
Checks if user has specific roleParameters:
role_name(string): Group name to check
Returns all roles/types for this userReturns: List of group names (e.g., [‘Student’, ‘Teacher’])Example:
Authentication
switch_to_user(request, user, retUrl, retTitle, onsite=False)
Morphs into another user (admin feature)Parameters:
request: Django request objectuser(ESPUser): User to becomeretUrl(string): URL to return to when switching backretTitle(string): Display text for return linkonsite(bool): Whether this is onsite morphing
Returns to original user after morphingReturns: URL to redirect to
Checks if currently morphed as another userReturns: True if session contains morph data
Usage Examples
Creating Users
Checking User Classes
Managing Availability
Related Models
- Program - Programs users participate in
- ClassSubject - Classes users teach or take
- Registration - Student enrollments
ContactInfo- Phone numbers and addressesStudentInfo- Student-specific data (grade, school)TeacherInfo- Teacher-specific data (bio, availability)