diff --git a/CDC_Backend/APIs/companyViews.py b/CDC_Backend/APIs/companyViews.py index c03f695..f7a7a76 100644 --- a/CDC_Backend/APIs/companyViews.py +++ b/CDC_Backend/APIs/companyViews.py @@ -1,6 +1,7 @@ import json from rest_framework.decorators import api_view +from django.forms.models import model_to_dict from .models import * from .utils import * @@ -245,16 +246,35 @@ def verifyEmail(request): raise ValueError("Invalid Email") opening.email_verified = True 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: 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"}, status=status.HTTP_200_OK) except Http404: diff --git a/CDC_Backend/APIs/constants.py b/CDC_Backend/APIs/constants.py index 0fca0ae..69bccf1 100644 --- a/CDC_Backend/APIs/constants.py +++ b/CDC_Backend/APIs/constants.py @@ -36,14 +36,14 @@ TOTAL_BRANCHES = 4 # Total No of Branches TOTAL_BATCHES = 4 # Total No of Batches # 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 -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_RESUME = "https://storage.googleapis.com/cdc-backend-attachments/resume/" 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" @@ -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', 'Resume', 'Selected', ] + +PDF_FILES_SERVING_ENDPOINT = 'http://localhost:5500/CDC_Backend/Storage/Company_Attachments/' # TODO: Change this to actual URL \ No newline at end of file diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index 1abe829..d417b2e 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -1,4 +1,5 @@ import datetime +import json import logging import os import random @@ -136,7 +137,9 @@ def saveFile(file, location): @background_task.background(schedule=10) def sendEmail(email_to, subject, data, template): 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) email_from = settings.EMAIL_HOST_USER diff --git a/CDC_Backend/templates/company_opening_submitted.html b/CDC_Backend/templates/company_opening_submitted.html index a37c107..8e88c69 100644 --- a/CDC_Backend/templates/company_opening_submitted.html +++ b/CDC_Backend/templates/company_opening_submitted.html @@ -21,6 +21,14 @@ table, td, div, h1, p { 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; + } + @@ -47,13 +55,44 @@ We have received your {{ opening_type }} notification for a {{ designation }} offer at {{ company_name }}. Click here to view your notification.

-

We will keep you informed with the updates. If you have any queries, please feel to write to cdc@iitdh.ac.in

+ + {% for key, value in data.items %} + + + + + {% endfor %} +
+ {{ key }} + + {% if 'list' in value.type %} + + {% for item in value.details %} +
  • + {% if 'link' in value.type and value.link %} + {{ item }} + {% elif 'link' in value.type %} + {{ item }} + {% else %} + {{ item }} + {% endif %} +
  • + {% endfor %} + {% else %} + {% if 'link' in value.type %} + {{ value.details }} + {% else %} + {{ value }} + {% endif %} + {% endif %} + +