From afd61d8ef45e65f1bccc1d3e4d12e2167b64c1b1 Mon Sep 17 00:00:00 2001 From: karthik murakonda Date: Thu, 28 Jul 2022 11:37:09 +0530 Subject: [PATCH] fixed: email not sending when application is edit - indexed id for student. --- CDC_Backend/APIs/adminViews.py | 13 ++++++------ CDC_Backend/APIs/models.py | 4 ++-- .../student_application_updated.html | 20 ++++++++++++------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index 99e01d4..3884ea9 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -229,8 +229,7 @@ def submitApplication(request, id, email, user_type): data = request.data student = get_object_or_404(Student, pk=data[STUDENT_ID]) opening = get_object_or_404(Placement, pk=data[OPENING_ID]) - user = get_object_or_404(User, pk=data[STUDENT_ID]) - + student_user = get_object_or_404(User, id = student.id) if data[APPLICATION_ID] == "": application = PlacementApplication() application.id = generateRandomString() @@ -253,9 +252,9 @@ def submitApplication(request, id, email, user_type): "application_type": "Placement", "additional_info": dict(json.loads(application.additional_info)), } + subject = STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) application.changed_by = get_object_or_404(User, id=id) - application.save() - sendEmail(user.email, STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT, data, STUDENT_APPLICATION_SUBMITTED_TEMPLATE) + sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_SUBMITTED_TEMPLATE) return Response({'action': "Add Student Application", 'message': "Application added"}, status=status.HTTP_200_OK) else: @@ -278,11 +277,13 @@ def submitApplication(request, id, email, user_type): "name": student.name, "company_name": opening.company_name, "application_type": "Placement", - "additional_info": dict(json.loads(application.additional_info)), + "resume": application.resume[16:], + "additional_info_items": dict(json.loads(application.additional_info)), } + subject = STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) application.changed_by = get_object_or_404(User, id=id) application.save() - sendEmail(user.email, STUDENT_APPLICATION_UPDATED_TEMPLATE_SUBJECT, data, STUDENT_APPLICATION_UPDATED_TEMPLATE) + sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_UPDATED_TEMPLATE) return Response({'action': "Add Student Application", 'message': "Application updated"}, status=status.HTTP_200_OK) else: diff --git a/CDC_Backend/APIs/models.py b/CDC_Backend/APIs/models.py index a5c1576..2b577ab 100644 --- a/CDC_Backend/APIs/models.py +++ b/CDC_Backend/APIs/models.py @@ -10,8 +10,8 @@ from .constants import * class User(models.Model): - email = models.EmailField(blank=False, max_length=JNF_TEXT_MAX_CHARACTER_COUNT, unique=True) - id = models.CharField(blank=False, max_length=25, index=True, unique=True) + email = models.EmailField(blank=False, max_length=JNF_TEXT_MAX_CHARACTER_COUNT, unique=True, primary_key=True) + id = models.CharField(blank=False, max_length=25, db_index=True) user_type = ArrayField(models.CharField(blank=False, max_length=10), size=4, default=list, blank=False) last_login_time = models.DateTimeField(default=timezone.now) history = HistoricalRecords() diff --git a/CDC_Backend/templates/student_application_updated.html b/CDC_Backend/templates/student_application_updated.html index d8e7408..2cb0246 100644 --- a/CDC_Backend/templates/student_application_updated.html +++ b/CDC_Backend/templates/student_application_updated.html @@ -48,16 +48,22 @@ We have received some update in your application for a {{ application_type }} offer at {{ company_name }}. - {% if additional_info_items %} - We received these additional details -
-

+ + + + + +
resume:{{ resume }}
+ {% if additional_info_items %} + We received these additional details +
- - {% for i,j in additional_info.items %} +

+ {% for i,j in additional_info_items.items %}

{{ i }}: