From bb552cbd3f8023e29c27d9567cadfae51c567d5a Mon Sep 17 00:00:00 2001
From: ismail
Job Title: {job.title}
+Application Deadline: {job.application_deadline.strftime('%B %d, %Y')}
+Current Applications: {application_count}
+Status: {job.get_status_display()}
+ +This job posting will close tomorrow. Please review any pending applications before the deadline.
+ + + +This is an automated reminder from the KAAUH Recruitment System.
+ + + """ + + # Send email to each recipient + for recipient_email in recipients: + _task_send_individual_email(subject, html_message, recipient_email, None, None, None) + + logger.info(f"Sent 1-day reminder for job {job_id} to {len(recipients)} recipients") + + except JobPosting.DoesNotExist: + logger.error(f"Job {job_id} not found for 1-day reminder") + except Exception as e: + logger.error(f"Error sending 1-day reminder for job {job_id}: {str(e)}") + + +def send_fifteen_minute_reminder(job_id): + """ + Send final email reminder 15 minutes before job application deadline. + """ + try: + job = JobPosting.objects.get(pk=job_id) + + # Only send if job is still active + if job.status != 'ACTIVE': + logger.info(f"Job {job_id} is no longer active, skipping 15-minute reminder") + return + + # Get application count + application_count = Application.objects.filter(job=job).count() + + # Determine recipients + recipients = [] + if job.assigned_to: + recipients.append(job.assigned_to.email) + + # Add admin users as fallback or additional recipients + admin_users = User.objects.filter(is_staff=True) + if not recipients: # If no assigned user, send to all admins + recipients = [admin.email for admin in admin_users] + + if not recipients: + logger.warning(f"No recipients found for job {job_id} 15-minute reminder") + return + + # Create email content + subject = f"FINAL REMINDER: Job '{job.title}' closes in 15 minutes" + + html_message = f""" + + +Job Title: {job.title}
+Application Deadline: {job.application_deadline.strftime('%B %d, %Y at %I:%M %p')}
+Current Applications: {application_count}
+Status: {job.get_status_display()}
+ +This job posting will close in 15 minutes. This is your final reminder to review any pending applications.
+ + + +This is an automated final reminder from the KAAUH Recruitment System.
+ + + """ + + # Send email to each recipient + for recipient_email in recipients: + _task_send_individual_email(subject, html_message, recipient_email, None, None, None) + + logger.info(f"Sent 15-minute reminder for job {job_id} to {len(recipients)} recipients") + + except JobPosting.DoesNotExist: + logger.error(f"Job {job_id} not found for 15-minute reminder") + except Exception as e: + logger.error(f"Error sending 15-minute reminder for job {job_id}: {str(e)}") + + +def send_job_closed_notification(job_id): + """ + Send notification when job has closed and update job status. + """ + try: + job = JobPosting.objects.get(pk=job_id) + + # Only proceed if job is currently active + if job.status != 'ACTIVE': + logger.info(f"Job {job_id} is already not active, skipping closed notification") + return + + # Get final application count + application_count = Application.objects.filter(job=job).count() + + # Update job status to closed + job.status = 'CLOSED' + job.save(update_fields=['status']) + + # Also close the form template + if job.template_form: + job.template_form.is_active = False + job.template_form.save(update_fields=['is_active']) + + # Determine recipients + recipients = [] + if job.assigned_to: + recipients.append(job.assigned_to.email) + + # Add admin users as fallback or additional recipients + admin_users = User.objects.filter(is_staff=True) + if not recipients: # If no assigned user, send to all admins + recipients = [admin.email for admin in admin_users] + + if not recipients: + logger.warning(f"No recipients found for job {job_id} closed notification") + return + + # Create email content + subject = f"Job '{job.title}' has closed - {application_count} applications received" + + html_message = f""" + + +Job Title: {job.title}
+Application Deadline: {job.application_deadline.strftime('%B %d, %Y at %I:%M %p')}
+Total Applications Received: {application_count}
+Status: {job.get_status_display()}
+ +The job posting has been automatically closed and is no longer accepting applications.
+ + + + +This is an automated notification from the KAAUH Recruitment System.
+ + + """ + + # Send email to each recipient + for recipient_email in recipients: + _task_send_individual_email(subject, html_message, recipient_email, None, None, None) + + logger.info(f"Sent job closed notification for job {job_id} to {len(recipients)} recipients") + + except JobPosting.DoesNotExist: + logger.error(f"Job {job_id} not found for closed notification") + except Exception as e: + logger.error(f"Error sending job closed notification for job {job_id}: {str(e)}") diff --git a/recruitment/urls.py b/recruitment/urls.py index c5b4ecb..9c2c256 100644 --- a/recruitment/urls.py +++ b/recruitment/urls.py @@ -264,11 +264,11 @@ urlpatterns = [ # path('api/templates/save/', views.save_form_template, name='save_form_template'), # path('api/templates/