process_job_questions
Processes job applicant question answers after a Job Applicant document is inserted.Function Signature
Parameters
The Job Applicant document instance
The document event method name (“after_insert”)
Behavior
- Validates Input: Checks if
custom_job_question_answersexists on the document - Parses Answers: Converts JSON string of answers to Python dictionary
- Retrieves Question Set: Fetches the Job Question Set linked to the job opening
- Stores Individual Answers: Creates child table records for each question/answer pair
- Calculates Score: Computes applicant score based on “Yes” answers (0-10 scale)
- Saves Document: Updates the Job Applicant with answers and score
Scoring Algorithm
- Each “Yes” answer contributes to the total score
- Final score is normalized to a 0-10 scale
- Example: If 3 out of 5 questions answered “Yes”, score = (10/5) * 3 = 6.0
Implementation
handlers.py
validate
Validates that all required questions have been answered before saving a Job Applicant.Function Signature
Parameters
The Job Applicant document being validated
The document event method name (“validate”)
Behavior
- Checks for Answers: Returns early if no answers provided
- Parses Answer Data: Converts JSON to dictionary
- Retrieves Question Set: Gets questions from the job opening
- Validates Required Fields: Ensures all required questions are answered
- Throws Error: Raises validation error with specific missing question
Validation Logic
- Iterates through all questions in the Question Set
- For each required question, checks if answer exists in submitted data
- Throws user-friendly error message if validation fails
Implementation
handlers.py
Error Example
Usage in Hooks
These handlers are registered inhooks.py:
The
validate function is not currently hooked but can be added to doc_events if needed: