Add email preview functionality for candidate details: allow users to preview email content before sending

This commit is contained in:
Ross
2025-12-22 10:26:22 +00:00
parent 54e1cf4ce0
commit 7b47a75657
3 changed files with 51 additions and 22 deletions
+17 -1
View File
@@ -5043,8 +5043,24 @@ def candidate_email_details(request, cid, resend=False):
except Exception:
resend_flag = False
# Allow a preview mode which returns the generated email body without
# actually sending the email. Useful for reviewing content in the UI.
preview_flag = False
try:
if request.method == 'POST':
preview_flag = str(request.POST.get('preview', '')).lower() in ('1', 'true', 'yes')
else:
preview_flag = str(request.GET.get('preview', '')).lower() in ('1', 'true', 'yes')
except Exception:
preview_flag = False
if preview_flag:
# Return plaintext body for preview (opens cleanly in a new tab/window)
msg = user.generate_email_details_msg()
return HttpResponse(msg, content_type='text/plain')
email_sent, comment = user.email_details(resend=resend_flag)
logger.debug(f"Email details sent to CID {cid}: sent={email_sent}, comment={comment}")
return JsonResponse({"sent": email_sent, "comment": str(comment)})