Send alert email to cdc when error while submitting jnf by company
This commit is contained in:
parent
6a3b5042b1
commit
805c0e0154
|
@ -230,12 +230,14 @@ def addPlacement(request):
|
||||||
status=status.HTTP_200_OK)
|
status=status.HTTP_200_OK)
|
||||||
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
exception_email(opening)
|
store_all_files(request)
|
||||||
|
exception_email(data)
|
||||||
logger.info("ValueError in addPlacement: " + str(e))
|
logger.info("ValueError in addPlacement: " + str(e))
|
||||||
return Response({'action': "Add Placement", 'message': str(e)},
|
return Response({'action': "Add Placement", 'message': str(e)},
|
||||||
status=status.HTTP_400_BAD_REQUEST)
|
status=status.HTTP_400_BAD_REQUEST)
|
||||||
except:
|
except:
|
||||||
exception_email(opening)
|
store_all_files(request)
|
||||||
|
exception_email(data)
|
||||||
logger.warning("Add New Placement: " + str(sys.exc_info()))
|
logger.warning("Add New Placement: " + str(sys.exc_info()))
|
||||||
return Response({'action': "Add Placement", 'message': "Something went wrong"},
|
return Response({'action': "Add Placement", 'message': "Something went wrong"},
|
||||||
status=status.HTTP_400_BAD_REQUEST)
|
status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
|
@ -150,6 +150,7 @@ SPECIAL_FORMAT_IN_PDF = ['website', 'company_details_pdf_names', 'description_pd
|
||||||
'compensation_details_pdf_names',
|
'compensation_details_pdf_names',
|
||||||
'selection_procedure_details_pdf_names']
|
'selection_procedure_details_pdf_names']
|
||||||
|
|
||||||
|
COMPANY_OPENING_ERROR_TEMPLATE = "Alert! Error submitting opening for {company_name}."
|
||||||
COMPANY_OPENING_SUBMITTED_TEMPLATE_SUBJECT = "Notification Submitted - {id} - Career Development Cell, IIT Dharwad"
|
COMPANY_OPENING_SUBMITTED_TEMPLATE_SUBJECT = "Notification Submitted - {id} - Career Development Cell, IIT Dharwad"
|
||||||
STUDENT_APPLICATION_STATUS_TEMPLATE_SUBJECT = 'Application Status - {company_name} - {id}'
|
STUDENT_APPLICATION_STATUS_TEMPLATE_SUBJECT = 'Application Status - {company_name} - {id}'
|
||||||
STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT = 'CDC - Application Submitted - {company_name}'
|
STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT = 'CDC - Application Submitted - {company_name}'
|
||||||
|
|
|
@ -57,6 +57,7 @@ def precheck(required_data=None):
|
||||||
|
|
||||||
return view_func(request, *args, **kwargs)
|
return view_func(request, *args, **kwargs)
|
||||||
except:
|
except:
|
||||||
|
logger.warning("Pre check: " + str(sys.exc_info()))
|
||||||
return Response({'action': "Pre check", 'message': "Something went wrong"},
|
return Response({'action': "Pre check", 'message': "Something went wrong"},
|
||||||
status=status.HTTP_400_BAD_REQUEST)
|
status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
@ -264,8 +265,13 @@ def verify_recaptcha(request):
|
||||||
|
|
||||||
|
|
||||||
def opening_description_table_html(opening):
|
def opening_description_table_html(opening):
|
||||||
|
# check typing of opening
|
||||||
|
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
|
||||||
|
else: #if isinstance(opening, QueryDict):
|
||||||
|
details = opening
|
||||||
keys = list(details.keys())
|
keys = list(details.keys())
|
||||||
newdetails = {}
|
newdetails = {}
|
||||||
for key in keys:
|
for key in keys:
|
||||||
|
@ -333,17 +339,40 @@ def send_opening_notifications(placement_id):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def exception_email(opening):
|
def exception_email(opening):
|
||||||
|
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_SUBMITTED_TEMPLATE_SUBJECT.format(id=opening.id), 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):
|
||||||
|
files = request.FILES
|
||||||
|
data = request.data
|
||||||
|
# save all the files
|
||||||
|
if files:
|
||||||
|
# company details pdf
|
||||||
|
for file in files.getlist(COMPANY_DETAILS_PDF):
|
||||||
|
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + "temp" + '/'
|
||||||
|
saveFile(file, file_location)
|
||||||
|
# compensation details pdf
|
||||||
|
for file in files.getlist(COMPENSATION_DETAILS_PDF):
|
||||||
|
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + "temp" + '/'
|
||||||
|
saveFile(file, file_location)
|
||||||
|
# selection procedure details pdf
|
||||||
|
for file in files.getlist(SELECTION_PROCEDURE_DETAILS_PDF):
|
||||||
|
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + "temp" + '/'
|
||||||
|
saveFile(file, file_location)
|
||||||
|
# description pdf
|
||||||
|
for file in files.getlist(DESCRIPTION_PDF):
|
||||||
|
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + "temp" + '/'
|
||||||
|
saveFile(file, file_location)
|
Loading…
Reference in New Issue