sending emails to eligible students only and setting proper deadline.
This commit is contained in:
parent
290639c032
commit
7845707348
|
@ -42,7 +42,7 @@ class Student(models.Model):
|
||||||
@property
|
@property
|
||||||
def _history_user(self):
|
def _history_user(self):
|
||||||
return self.changed_by
|
return self.changed_by
|
||||||
|
|
||||||
@_history_user.setter
|
@_history_user.setter
|
||||||
def _history_user(self, value):
|
def _history_user(self, value):
|
||||||
if isinstance(value, User):
|
if isinstance(value, User):
|
||||||
|
@ -51,7 +51,6 @@ class Student(models.Model):
|
||||||
self.changed_by = None
|
self.changed_by = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Admin(models.Model):
|
class Admin(models.Model):
|
||||||
id = models.CharField(blank=False, max_length=15, primary_key=True)
|
id = models.CharField(blank=False, max_length=15, primary_key=True)
|
||||||
name = models.CharField(blank=False, max_length=JNF_TEXT_MAX_CHARACTER_COUNT)
|
name = models.CharField(blank=False, max_length=JNF_TEXT_MAX_CHARACTER_COUNT)
|
||||||
|
@ -61,7 +60,7 @@ class Admin(models.Model):
|
||||||
@property
|
@property
|
||||||
def _history_user(self):
|
def _history_user(self):
|
||||||
return self.changed_by
|
return self.changed_by
|
||||||
|
|
||||||
@_history_user.setter
|
@_history_user.setter
|
||||||
def _history_user(self, value):
|
def _history_user(self, value):
|
||||||
if isinstance(value, User):
|
if isinstance(value, User):
|
||||||
|
@ -71,7 +70,8 @@ class Admin(models.Model):
|
||||||
|
|
||||||
|
|
||||||
def two_day_after_today():
|
def two_day_after_today():
|
||||||
return timezone.now() + timezone.timedelta(days=2)
|
# round off to nearest day
|
||||||
|
return timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + timezone.timedelta(days=2)
|
||||||
|
|
||||||
|
|
||||||
class Placement(models.Model):
|
class Placement(models.Model):
|
||||||
|
@ -145,7 +145,8 @@ class Placement(models.Model):
|
||||||
created_at = models.DateTimeField(blank=False, default=None, null=True)
|
created_at = models.DateTimeField(blank=False, default=None, null=True)
|
||||||
updated_at = models.DateTimeField(blank=False, default=None, null=True)
|
updated_at = models.DateTimeField(blank=False, default=None, null=True)
|
||||||
changed_by = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
|
changed_by = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
|
||||||
history = HistoricalRecords(user_model=User)
|
history = HistoricalRecords(user_model=User)
|
||||||
|
|
||||||
def format(self):
|
def format(self):
|
||||||
if self.company_name is not None:
|
if self.company_name is not None:
|
||||||
self.company_name = self.company_name.strip()[:JNF_SMALLTEXT_MAX_CHARACTER_COUNT]
|
self.company_name = self.company_name.strip()[:JNF_SMALLTEXT_MAX_CHARACTER_COUNT]
|
||||||
|
@ -187,12 +188,13 @@ class Placement(models.Model):
|
||||||
if self.other_requirements is not None:
|
if self.other_requirements is not None:
|
||||||
self.other_requirements = self.other_requirements.strip()[:JNF_TEXTAREA_MAX_CHARACTER_COUNT]
|
self.other_requirements = self.other_requirements.strip()[:JNF_TEXTAREA_MAX_CHARACTER_COUNT]
|
||||||
if self.additional_info is not None:
|
if self.additional_info is not None:
|
||||||
self.additional_info = [info.strip()[:JNF_TEXTMEDIUM_MAX_CHARACTER_COUNT] for info in list(self.additional_info)]
|
self.additional_info = [info.strip()[:JNF_TEXTMEDIUM_MAX_CHARACTER_COUNT] for info in
|
||||||
|
list(self.additional_info)]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _history_user(self):
|
def _history_user(self):
|
||||||
return self.changed_by
|
return self.changed_by
|
||||||
|
|
||||||
@_history_user.setter
|
@_history_user.setter
|
||||||
def _history_user(self, value):
|
def _history_user(self, value):
|
||||||
if isinstance(value, User):
|
if isinstance(value, User):
|
||||||
|
@ -235,14 +237,14 @@ class PlacementApplication(models.Model):
|
||||||
@property
|
@property
|
||||||
def _history_user(self):
|
def _history_user(self):
|
||||||
return self.changed_by
|
return self.changed_by
|
||||||
|
|
||||||
@_history_user.setter
|
@_history_user.setter
|
||||||
def _history_user(self, value):
|
def _history_user(self, value):
|
||||||
if isinstance(value, User):
|
if isinstance(value, User):
|
||||||
self.changed_by = value
|
self.changed_by = value
|
||||||
else:
|
else:
|
||||||
self.changed_by = None
|
self.changed_by = None
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name_plural = "Placement Applications"
|
verbose_name_plural = "Placement Applications"
|
||||||
unique_together = ('placement_id', 'student_id')
|
unique_together = ('placement_id', 'student_id')
|
||||||
|
@ -267,7 +269,7 @@ class PrePlacementOffer(models.Model):
|
||||||
@property
|
@property
|
||||||
def _history_user(self):
|
def _history_user(self):
|
||||||
return self.changed_by
|
return self.changed_by
|
||||||
|
|
||||||
@_history_user.setter
|
@_history_user.setter
|
||||||
def _history_user(self, value):
|
def _history_user(self, value):
|
||||||
if isinstance(value, User):
|
if isinstance(value, User):
|
||||||
|
|
|
@ -270,9 +270,9 @@ def opening_description_table_html(opening):
|
||||||
# check typing of opening
|
# check typing of opening
|
||||||
if isinstance(opening, Placement):
|
if isinstance(opening, Placement):
|
||||||
details = model_to_dict(opening, fields=[field.name for field in Placement._meta.fields],
|
details = model_to_dict(opening, fields=[field.name for field in Placement._meta.fields],
|
||||||
exclude=EXCLUDE_IN_PDF)
|
exclude=EXCLUDE_IN_PDF)
|
||||||
# check typing of opening is query dict
|
# check typing of opening is query dict
|
||||||
else: #if isinstance(opening, QueryDict):
|
else: # if isinstance(opening, QueryDict):
|
||||||
details = opening
|
details = opening
|
||||||
keys = list(details.keys())
|
keys = list(details.keys())
|
||||||
newdetails = {}
|
newdetails = {}
|
||||||
|
@ -318,44 +318,48 @@ def send_opening_notifications(placement_id):
|
||||||
placement = get_object_or_404(Placement, id=placement_id)
|
placement = get_object_or_404(Placement, id=placement_id)
|
||||||
students = Student.objects.all()
|
students = Student.objects.all()
|
||||||
for student in students.iterator():
|
for student in students.iterator():
|
||||||
if PlacementApplicationConditions(student, placement)[0]:
|
if student.branch in placement.allowed_branch:
|
||||||
try:
|
if student.degree == 'bTech' or placement.rs_eligible is True:
|
||||||
student_user = get_object_or_404(User, id=student.id)
|
if PlacementApplicationConditions(student, placement)[0]:
|
||||||
subject = NOTIFY_STUDENTS_OPENING_TEMPLATE_SUBJECT.format(company_name=placement.company_name)
|
try:
|
||||||
data = {
|
student_user = get_object_or_404(User, id=student.id)
|
||||||
"company_name": placement.company_name,
|
subject = NOTIFY_STUDENTS_OPENING_TEMPLATE_SUBJECT.format(
|
||||||
"opening_type": 'Placement',
|
company_name=placement.company_name)
|
||||||
"designation": placement.designation,
|
data = {
|
||||||
"deadline": placement.deadline_datetime.strftime("%A, %-d %B %Y, %-I:%M %p"),
|
"company_name": placement.company_name,
|
||||||
"link": PLACEMENT_OPENING_URL.format(id=placement.id)
|
"opening_type": 'Placement',
|
||||||
}
|
"designation": placement.designation,
|
||||||
sendEmail(student_user.email, subject, data, NOTIFY_STUDENTS_OPENING_TEMPLATE)
|
"deadline": placement.deadline_datetime.strftime("%A, %-d %B %Y, %-I:%M %p"),
|
||||||
except Http404:
|
"link": PLACEMENT_OPENING_URL.format(id=placement.id)
|
||||||
logger.warning('Utils - send_opening_notifications: user not found : ' + student.id)
|
}
|
||||||
except Exception as e:
|
sendEmail(student_user.email, subject, data, NOTIFY_STUDENTS_OPENING_TEMPLATE)
|
||||||
logger.warning('Utils - send_opening_notifications: For Loop' + str(e))
|
except Http404:
|
||||||
|
logger.warning('Utils - send_opening_notifications: user not found : ' + student.id)
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning('Utils - send_opening_notifications: For Loop' + str(e))
|
||||||
|
|
||||||
except:
|
except:
|
||||||
logger.warning('Utils - send_opening_notifications: ' + str(sys.exc_info()))
|
logger.warning('Utils - send_opening_notifications: ' + str(sys.exc_info()))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def exception_email(opening):
|
def exception_email(opening):
|
||||||
opening = opening.dict()
|
opening = opening.dict()
|
||||||
data = {
|
data = {
|
||||||
"designation": opening["designation"],
|
"designation": opening["designation"],
|
||||||
"opening_type": PLACEMENT,
|
"opening_type": PLACEMENT,
|
||||||
"company_name": opening["company_name"],
|
"company_name": opening["company_name"],
|
||||||
}
|
}
|
||||||
pdfhtml = opening_description_table_html(opening)
|
pdfhtml = opening_description_table_html(opening)
|
||||||
name = opening["company_name"]+'_jnf_response.pdf'
|
name = opening["company_name"] + '_jnf_response.pdf'
|
||||||
attachment_jnf_respone = {
|
attachment_jnf_respone = {
|
||||||
"name": name,
|
"name": name,
|
||||||
"html": pdfhtml,
|
"html": pdfhtml,
|
||||||
}
|
}
|
||||||
|
|
||||||
sendEmail(CDC_MAIl_ADDRESS, COMPANY_OPENING_ERROR_TEMPLATE.format(company_name=opening["company_name"]), data,
|
sendEmail(CDC_MAIl_ADDRESS, COMPANY_OPENING_ERROR_TEMPLATE.format(company_name=opening["company_name"]), data,
|
||||||
COMPANY_OPENING_SUBMITTED_TEMPLATE, attachment_jnf_respone)
|
COMPANY_OPENING_SUBMITTED_TEMPLATE, attachment_jnf_respone)
|
||||||
|
|
||||||
|
|
||||||
def store_all_files(request):
|
def store_all_files(request):
|
||||||
files = request.FILES
|
files = request.FILES
|
||||||
|
@ -377,4 +381,4 @@ def store_all_files(request):
|
||||||
# description pdf
|
# description pdf
|
||||||
for file in files.getlist(DESCRIPTION_PDF):
|
for file in files.getlist(DESCRIPTION_PDF):
|
||||||
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + "temp" + '/'
|
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + "temp" + '/'
|
||||||
saveFile(file, file_location)
|
saveFile(file, file_location)
|
||||||
|
|
Loading…
Reference in New Issue