Send alert email to cdc when error while submitting jnf by company

This commit is contained in:
karthikmurakonda 2022-08-31 12:48:20 +05:30
parent 6a3b5042b1
commit 805c0e0154
3 changed files with 39 additions and 7 deletions

View File

@ -230,12 +230,14 @@ def addPlacement(request):
status=status.HTTP_200_OK)
except ValueError as e:
exception_email(opening)
store_all_files(request)
exception_email(data)
logger.info("ValueError in addPlacement: " + str(e))
return Response({'action': "Add Placement", 'message': str(e)},
status=status.HTTP_400_BAD_REQUEST)
except:
exception_email(opening)
store_all_files(request)
exception_email(data)
logger.warning("Add New Placement: " + str(sys.exc_info()))
return Response({'action': "Add Placement", 'message': "Something went wrong"},
status=status.HTTP_400_BAD_REQUEST)

View File

@ -150,6 +150,7 @@ SPECIAL_FORMAT_IN_PDF = ['website', 'company_details_pdf_names', 'description_pd
'compensation_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"
STUDENT_APPLICATION_STATUS_TEMPLATE_SUBJECT = 'Application Status - {company_name} - {id}'
STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT = 'CDC - Application Submitted - {company_name}'

View File

@ -57,6 +57,7 @@ def precheck(required_data=None):
return view_func(request, *args, **kwargs)
except:
logger.warning("Pre check: " + str(sys.exc_info()))
return Response({'action': "Pre check", 'message': "Something went wrong"},
status=status.HTTP_400_BAD_REQUEST)
@ -264,8 +265,13 @@ def verify_recaptcha(request):
def opening_description_table_html(opening):
details = model_to_dict(opening, fields=[field.name for field in Placement._meta.fields],
# check typing of opening
if isinstance(opening, Placement):
details = model_to_dict(opening, fields=[field.name for field in Placement._meta.fields],
exclude=EXCLUDE_IN_PDF)
# check typing of opening is query dict
else: #if isinstance(opening, QueryDict):
details = opening
keys = list(details.keys())
newdetails = {}
for key in keys:
@ -333,17 +339,40 @@ def send_opening_notifications(placement_id):
return False
def exception_email(opening):
opening = opening.dict()
data = {
"designation": opening.designation,
"designation": opening["designation"],
"opening_type": PLACEMENT,
"company_name": opening.company_name,
"company_name": opening["company_name"],
}
pdfhtml = opening_description_table_html(opening)
name = opening.company_name + '_jnf_response.pdf'
name = opening["company_name"]+'_jnf_response.pdf'
attachment_jnf_respone = {
"name": name,
"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)
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)