HR-ATS-Portal/backend/candidate_forms/serializers.py

33 lines
1.4 KiB
Python

def serialize_form(
row,
*,
candidate_name=None,
job_title=None,
interviewer_name=None,
created_by_name=None,
) -> dict:
"""`candidate_name` / `job_title` / user names come from one batched lookup
in views — never a lazy per-row load."""
return {
"id": str(row.id) if row.id else None,
"inbox_id": row.inbox_id,
"manual_upload_candidate_id": (
str(row.manual_upload_candidate_id) if row.manual_upload_candidate_id else None
),
"job_post_id": str(row.job_post_id) if row.job_post_id else None,
"candidate_name": candidate_name,
"job_title": job_title,
"form_type": row.form_type,
"interviewer_id": str(row.interviewer_id) if row.interviewer_id else None,
"interviewer_name": interviewer_name,
"form_date": row.form_date.isoformat() if row.form_date else None,
"sections": list(row.sections) if row.sections else None,
"fields": dict(row.fields) if row.fields else {},
"overall_score": row.overall_score,
"recommendation": row.recommendation,
"created_by": str(row.created_by) if row.created_by else None,
"created_by_name": created_by_name,
"created_at": row.created_at.isoformat() if row.created_at else None,
"updated_at": row.updated_at.isoformat() if row.updated_at else None,
}