email jnf response to company

This commit is contained in:
karthik murakonda 2022-04-30 01:28:25 +05:30
parent 0038c9dbe2
commit a12b2f2a2c
4 changed files with 77 additions and 13 deletions

View File

@ -1,6 +1,7 @@
import json import json
from rest_framework.decorators import api_view from rest_framework.decorators import api_view
from django.forms.models import model_to_dict
from .models import * from .models import *
from .utils import * from .utils import *
@ -245,16 +246,35 @@ def verifyEmail(request):
raise ValueError("Invalid Email") raise ValueError("Invalid Email")
opening.email_verified = True opening.email_verified = True
opening.save() opening.save()
data = {
"designation": opening.designation,
"opening_type": PLACEMENT,
"opening_link": PLACEMENT_OPENING_URL.format(id=opening.id), # Some Changes here too
"company_name": opening.company_name
}
sendEmail(opening.email, COMPANY_OPENING_SUBMITTED_TEMPLATE_SUBJECT.format(id=opening.id), data,
COMPANY_OPENING_SUBMITTED_TEMPLATE)
else: else:
raise ValueError('Invalid opening type') raise ValueError('Invalid opening type')
# Email sending part.
details = model_to_dict(opening, fields = [field.name for field in Placement._meta.fields], exclude = ['id','is_company_details_pdf','offer_accepted','is_description_pdf','is_compensation_details_pdf','is_selection_procedure_details_pdf','email_verified'])
keys = list(details.keys())
newdetails = {}
for key in keys:
if isinstance(details[key], list):
details[key] = {"details": details[key], "type": ["list"]}
if key in ['website','company_details_pdf_names','description_pdf_names','compensation_details_pdf_names','selection_procedure_pdf_names']:
if key == 'website':
details[key] = {"details": details[key], "type": ["link"]}
else:
details[key] = {"details": details[key]["details"], "type": ["list","link"], "link": PDF_FILES_SERVING_ENDPOINT+opening.id+"/"}
new_key = key.replace('_',' ')
if key == 'company_details_pdf_names':
new_key = 'company details pdf'
newdetails[new_key] = details[key]
data = {
"designation": opening.designation,
"opening_type": PLACEMENT,
"opening_link": PLACEMENT_OPENING_URL.format(id=opening.id), # Some Changes here too
"company_name": opening.company_name,
"data":newdetails
}
json_data = json.dumps(data,default=str)
sendEmail(opening.email, COMPANY_OPENING_SUBMITTED_TEMPLATE_SUBJECT.format(id=opening.id), json_data,
COMPANY_OPENING_SUBMITTED_TEMPLATE)
return Response({'action': "Verify Email", 'message': "Email Verified Successfully"}, return Response({'action': "Verify Email", 'message': "Email Verified Successfully"},
status=status.HTTP_200_OK) status=status.HTTP_200_OK)
except Http404: except Http404:

View File

@ -36,14 +36,14 @@ TOTAL_BRANCHES = 4 # Total No of Branches
TOTAL_BATCHES = 4 # Total No of Batches TOTAL_BATCHES = 4 # Total No of Batches
# To be Configured Properly # To be Configured Properly
CLIENT_ID = "956830229554-290mirc16pdhd5j7ph7v7ukibo4t1qcp.apps.googleusercontent.com" # Google Login Client ID CLIENT_ID = "628308091838-nvfn455vabbq7j0odd797sls8itpplmr.apps.googleusercontent.com" # Google Login Client ID
# To be Configured Properly # To be Configured Properly
PLACEMENT_OPENING_URL = "https://www.googleapis.com/auth/adwords/{id}" # On frontend, this is the URL to be opened PLACEMENT_OPENING_URL = "https://www.googleapis.com/auth/adwords/{id}" # On frontend, this is the URL to be opened TODO: Change this to the correct URL
LINK_TO_STORAGE_COMPANY_ATTACHMENT = "https://storage.googleapis.com/cdc-backend-attachments/company_attachments/" LINK_TO_STORAGE_COMPANY_ATTACHMENT = "https://storage.googleapis.com/cdc-backend-attachments/company_attachments/"
LINK_TO_STORAGE_RESUME = "https://storage.googleapis.com/cdc-backend-attachments/resume/" LINK_TO_STORAGE_RESUME = "https://storage.googleapis.com/cdc-backend-attachments/resume/"
LINK_TO_APPLICATIONS_CSV = "https://storage.googleapis.com/cdc-backend-attachments/applications-csv/" LINK_TO_APPLICATIONS_CSV = "https://storage.googleapis.com/cdc-backend-attachments/applications-csv/"
LINK_TO_EMAIl_VERIFICATION_API = "https://api.sendgrid.com/v3/mail/send?token={token}" LINK_TO_EMAIl_VERIFICATION_API = "https://localhost:3000/company/verifyemail?token={token}" # TODO: Change this to actual URL
EMAIL = "email" EMAIL = "email"
@ -137,3 +137,5 @@ COMPANY_EMAIL_VERIFICATION_TEMPLATE = 'company_email_verification.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', ]
PDF_FILES_SERVING_ENDPOINT = 'http://localhost:5500/CDC_Backend/Storage/Company_Attachments/' # TODO: Change this to actual URL

View File

@ -1,4 +1,5 @@
import datetime import datetime
import json
import logging import logging
import os import os
import random import random
@ -136,7 +137,9 @@ def saveFile(file, location):
@background_task.background(schedule=10) @background_task.background(schedule=10)
def sendEmail(email_to, subject, data, template): def sendEmail(email_to, subject, data, template):
try: try:
html_content = render_to_string(template, data) # render with dynamic value if not isinstance(data, dict):
data = json.loads(data)
html_content = render_to_string(template, ndata) # render with dynamic value
text_content = strip_tags(html_content) text_content = strip_tags(html_content)
email_from = settings.EMAIL_HOST_USER email_from = settings.EMAIL_HOST_USER

View File

@ -21,6 +21,14 @@
table, td, div, h1, p { table, td, div, h1, p {
font-family: 'Roboto', sans-serif; font-family: 'Roboto', sans-serif;
} }
#details_table tr:nth-child(even) {background: #FFF}
#details_table tr:nth-child(odd) {background: #f9f9f9}
#details_table td {padding: 10px}
#details_table{
border: #334878 1px solid;
border-collapse: collapse;
}
</style> </style>
</head> </head>
@ -47,13 +55,44 @@
We have received your <b>{{ opening_type }}</b> notification for a <b>{{ designation }}</b> offer at <b> We have received your <b>{{ opening_type }}</b> notification for a <b>{{ designation }}</b> offer at <b>
{{ company_name }}</b>. Click <a href="{{ opening_link }}">here</a> to view your notification. {{ company_name }}</b>. Click <a href="{{ opening_link }}">here</a> to view your notification.
</p> </p>
<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;">
We will keep you informed with the updates. If you have any queries, please We will keep you informed with the updates. If you have any queries, please
feel to feel to
write to write to
<nobr><u>cdc@iitdh.ac.in</u></nobr> <nobr><u>cdc@iitdh.ac.in</u></nobr>
</p> </p>
<table id="details_table">
{% for key, value in data.items %}
<tr>
<td >
{{ key }}
</td>
<td>
{% if 'list' in value.type %}
{% for item in value.details %}
<li>
{% if 'link' in value.type and value.link %}
<a href="{{value.link|add:item}}">{{ item }}</a>
{% elif 'link' in value.type %}
<a href="{{item}}">{{ item }}</a>
{% else %}
{{ item }}
{% endif %}
</li>
{% endfor %}
{% else %}
{% if 'link' in value.type %}
<a href="{{ value.details }}">{{ value.details }}</a>
{% else %}
{{ value }}
{% endif %}
{% endif %}
</td>
</tr>
{% endfor %}
</table>
</td> </td>
</tr> </tr>