Merge pull request #145 from CDC-IITDH/gowtham/send-reminder-mails
Send reminder mails service
This commit is contained in:
commit
ba8395c522
|
@ -158,6 +158,7 @@ STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT = 'CDC - Application Submitted -
|
||||||
STUDENT_APPLICATION_UPDATED_TEMPLATE_SUBJECT = 'CDC - Application Updated - {company_name}'
|
STUDENT_APPLICATION_UPDATED_TEMPLATE_SUBJECT = 'CDC - Application Updated - {company_name}'
|
||||||
COMPANY_EMAIl_VERIFICATION_TEMPLATE_SUBJECT = 'Email Verification - Career Development Cell, IIT Dharwad'
|
COMPANY_EMAIl_VERIFICATION_TEMPLATE_SUBJECT = 'Email Verification - Career Development Cell, IIT Dharwad'
|
||||||
NOTIFY_STUDENTS_OPENING_TEMPLATE_SUBJECT = 'Placement Opportunity at {company_name}'
|
NOTIFY_STUDENTS_OPENING_TEMPLATE_SUBJECT = 'Placement Opportunity at {company_name}'
|
||||||
|
REMINDER_STUDENTS_OPENING_TEMPLATE_SUBJECT = 'Reminder - Placement Opportunity at {company_name}'
|
||||||
|
|
||||||
STUDENT_APPLICATION_SUBMITTED_TEMPLATE = 'student_application_submitted.html'
|
STUDENT_APPLICATION_SUBMITTED_TEMPLATE = 'student_application_submitted.html'
|
||||||
COMPANY_OPENING_SUBMITTED_TEMPLATE = 'company_opening_submitted.html'
|
COMPANY_OPENING_SUBMITTED_TEMPLATE = 'company_opening_submitted.html'
|
||||||
|
@ -167,6 +168,7 @@ STUDENT_APPLICATION_UPDATED_TEMPLATE = 'student_application_updated.html'
|
||||||
COMPANY_EMAIL_VERIFICATION_TEMPLATE = 'company_email_verification.html'
|
COMPANY_EMAIL_VERIFICATION_TEMPLATE = 'company_email_verification.html'
|
||||||
COMPANY_JNF_RESPONSE_TEMPLATE = 'company_jnf_response.html'
|
COMPANY_JNF_RESPONSE_TEMPLATE = 'company_jnf_response.html'
|
||||||
NOTIFY_STUDENTS_OPENING_TEMPLATE = 'notify_students_new_opening.html'
|
NOTIFY_STUDENTS_OPENING_TEMPLATE = 'notify_students_new_opening.html'
|
||||||
|
REMINDER_STUDENTS_OPENING_TEMPLATE = 'students_opening_reminder.html'
|
||||||
|
|
||||||
APPLICATION_CSV_COL_NAMES = ['Applied At', 'Roll No.', 'Name', 'Email', 'Phone Number', 'Branch', 'Batch', 'CPI',
|
APPLICATION_CSV_COL_NAMES = ['Applied At', 'Roll No.', 'Name', 'Email', 'Phone Number', 'Branch', 'Batch', 'CPI',
|
||||||
'Resume', 'Selected', ]
|
'Resume', 'Selected', ]
|
||||||
|
|
|
@ -47,7 +47,9 @@ INSTALLED_APPS = [
|
||||||
'background_task',
|
'background_task',
|
||||||
'simple_history',
|
'simple_history',
|
||||||
'import_export',
|
'import_export',
|
||||||
|
'django_extensions',
|
||||||
"django_extensions"
|
"django_extensions"
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
from APIs.models import Placement, Student, PlacementApplication, User
|
||||||
|
from APIs.utils import sendEmail, PlacementApplicationConditions
|
||||||
|
from APIs.constants import *
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.utils import timezone
|
||||||
|
import time
|
||||||
|
import pytz
|
||||||
|
|
||||||
|
REPEAT_AFTER = 10 * 60
|
||||||
|
|
||||||
|
|
||||||
|
def send_reminder_mails():
|
||||||
|
placements = Placement.objects.all()
|
||||||
|
students = Student.objects.all()
|
||||||
|
|
||||||
|
for placement in placements.iterator():
|
||||||
|
print("Processing placement: ", placement)
|
||||||
|
# if placement is approved and email is verified
|
||||||
|
if not (placement.offer_accepted and placement.email_verified):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# if placement is not expired
|
||||||
|
if placement.deadline_datetime < timezone.now():
|
||||||
|
continue
|
||||||
|
|
||||||
|
# send the reminder mail if the deadline is within 24 hours +- ReapetAfter
|
||||||
|
if timezone.now() - timezone.timedelta(
|
||||||
|
seconds=REPEAT_AFTER) <= placement.deadline_datetime - timezone.timedelta(days=1) < timezone.now() + \
|
||||||
|
timezone.timedelta(seconds=REPEAT_AFTER):
|
||||||
|
for student in students:
|
||||||
|
try:
|
||||||
|
# if Application not found then send email
|
||||||
|
if not PlacementApplication.objects.filter(placement=placement, student=student).exists():
|
||||||
|
if student.branch in placement.allowed_branch:
|
||||||
|
if student.degree == 'bTech' or placement.rs_eligible is True:
|
||||||
|
if PlacementApplicationConditions(student, placement)[0]:
|
||||||
|
student_user = get_object_or_404(User, id=student.id)
|
||||||
|
# change timezone to IST
|
||||||
|
deadline_datetime = placement.deadline_datetime.astimezone(pytz.timezone('Asia/Kolkata'))
|
||||||
|
data = {
|
||||||
|
"company_name": placement.company_name,
|
||||||
|
"opening_type": 'Placement',
|
||||||
|
"deadline": deadline_datetime.strftime("%A, %-d %B %Y, %-I:%M %p"),
|
||||||
|
"link": PLACEMENT_OPENING_URL.format(id=placement.id)
|
||||||
|
}
|
||||||
|
print("Sending mail to " + student_user.email, "placement id: ", placement.id)
|
||||||
|
sendEmail(student_user.email,
|
||||||
|
REMINDER_STUDENTS_OPENING_TEMPLATE_SUBJECT.format(
|
||||||
|
company_name=placement.company_name),
|
||||||
|
data, REMINDER_STUDENTS_OPENING_TEMPLATE)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
while True:
|
||||||
|
print("Sleeping for", REPEAT_AFTER, "seconds")
|
||||||
|
time.sleep(REPEAT_AFTER)
|
||||||
|
print("Running send_reminder_mails()")
|
||||||
|
send_reminder_mails()
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
<h1 style="font-size:24px;margin:0 0 20px 0;font-family: 'Roboto', sans-serif;
|
<h1 style="font-size:24px;margin:0 0 20px 0;font-family: 'Roboto', sans-serif;
|
||||||
">{{ opening_type }} Opportunity at {{ company_name }}</h1>
|
">{{ opening_type }} Opportunity at {{ company_name }}</h1>
|
||||||
<p style="margin:0 0 12px 0;font-size:16px;line-height:24px;font-family: 'Roboto', sans-serif;">
|
<p style="margin:0 0 12px 0;font-size:16px;line-height:24px;font-family: 'Roboto', sans-serif;">
|
||||||
Gentle reminder for the same.
|
Gentle reminder to fill out the application form.
|
||||||
Interested students can apply before <b>{{ deadline }}</b> in the <a
|
Interested students can apply before <b>{{ deadline }}</b> in the <a
|
||||||
href="{{ link }}">CDC-webportal</a>.
|
href="{{ link }}">CDC-webportal</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -14,6 +14,7 @@ django-background-tasks==1.2.5
|
||||||
django-compat==1.0.15
|
django-compat==1.0.15
|
||||||
django-cors-headers==3.11.0
|
django-cors-headers==3.11.0
|
||||||
django-db-logger==0.1.12
|
django-db-logger==0.1.12
|
||||||
|
django-extensions==3.2.1
|
||||||
django-import-export==2.8.0
|
django-import-export==2.8.0
|
||||||
django-simple-history==3.1.1
|
django-simple-history==3.1.1
|
||||||
djangorestframework==3.13.1
|
djangorestframework==3.13.1
|
||||||
|
|
Loading…
Reference in New Issue