From 1b20454f352b0dfa2b71764e80b0446a91a98555 Mon Sep 17 00:00:00 2001
From: gowtham3105 <66207607+gowtham3105@users.noreply.github.com>
Date: Sat, 23 Oct 2021 17:43:49 +0530
Subject: [PATCH] Created MarkStatus API
---
CDC_Backend/APIs/adminUrls.py | 3 +-
CDC_Backend/APIs/adminViews.py | 41 +++++++++
CDC_Backend/APIs/constants.py | 51 ++++++-----
CDC_Backend/APIs/models.py | 3 +-
CDC_Backend/APIs/studentViews.py | 28 +++---
CDC_Backend/APIs/utils.py | 30 +------
.../templates/company_opening_submitted.html | 85 +++++++++++++++++++
7 files changed, 180 insertions(+), 61 deletions(-)
create mode 100644 CDC_Backend/templates/company_opening_submitted.html
diff --git a/CDC_Backend/APIs/adminUrls.py b/CDC_Backend/APIs/adminUrls.py
index 203c0dc..72c32e9 100644
--- a/CDC_Backend/APIs/adminUrls.py
+++ b/CDC_Backend/APIs/adminUrls.py
@@ -1,7 +1,8 @@
from django.urls import path
-from . import companyViews
+from . import adminViews
urlpatterns = [
+ path('markStatus/', adminViews.markStatus, name="Mark Status"),
]
diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py
index e69de29..92b8ef9 100644
--- a/CDC_Backend/APIs/adminViews.py
+++ b/CDC_Backend/APIs/adminViews.py
@@ -0,0 +1,41 @@
+from .utils import *
+from rest_framework.decorators import api_view
+
+
+@api_view(['POST'])
+@isAuthorized([ADMIN])
+@precheck([OPENING_ID, STUDENT_LIST])
+def markStatus(request, id, email, user_type):
+ try:
+ data = request.data
+ applications = PlacementApplication.objects.filter(placement_id=data[OPENING_ID]) # Getting All
+ # application form db for this opening
+ for i in data[STUDENT_LIST]:
+ application = applications.filter(student_id=i[STUDENT_ID]) # Filtering student's application
+ if len(application) > 0:
+ application = application[0]
+ application.selected = i[STUDENT_STATUS]
+ application.save()
+ email = application.student.roll_no + "@iitdh.ac.in" # Only allowing for IITDh emails
+ subject = STUDENT_APPLICATION_STATUS_TEMPLATE_SUBJECT.format(company_name=application.placement.name,
+ id=application.id)
+ data = {
+ "company_name": application.placement.name,
+ "designation": application.placement.designation,
+ "student_name": application.student.name
+ }
+ if application.selected: # Sending corresponding email to students
+ sendEmail(email, subject, data, STUDENT_APPLICATION_STATUS_SELECTED_TEMPLATE)
+ # This one needs to be created
+ else:
+ sendEmail(email, subject, data, STUDENT_APPLICATION_STATUS_NOT_SELECTED_TEMPLATE)
+ # This one needs to be created
+ else:
+ raise ValueError("Student - " + i[STUDENT_ID] + " didn't apply for this opening")
+ except ValueError as e:
+ return Response({'action': "Mark Selected", 'message': str(e)},
+ status=status.HTTP_400_BAD_REQUEST)
+ except:
+ logger.warning("Mark Status: " + str(sys.exc_info()))
+ return Response({'action': "Mark Stauts", 'message': "Error Occurred!"},
+ status=status.HTTP_400_BAD_REQUEST)
diff --git a/CDC_Backend/APIs/constants.py b/CDC_Backend/APIs/constants.py
index 2ea330b..4911e8d 100644
--- a/CDC_Backend/APIs/constants.py
+++ b/CDC_Backend/APIs/constants.py
@@ -26,7 +26,6 @@ TIERS = [
['6', 'Tier 6']
]
-
TOTAL_BRANCHES = 3 # Total No of Branches
TOTAL_BATCHES = 4 # Total No of Batches
@@ -38,15 +37,16 @@ EMAIL = "email"
STUDENT = 'student'
ADMIN = 'Admin'
COMPANY = ''
+
STORAGE_DESTINATION = "./Storage/Resumes/"
STORAGE_DESTINATION_COMPANY_ATTACHMENTS = './Storage/Company_Attachments/'
RESUME_FILE_NAME = 'resume_file_name'
APPLICATION_ID = "application_id"
-APPLICATION_OPENING_TYPE = "opening_type"
-APPLICATION_OPENING_ID = "opening_id"
-APPLICATION_ADDITIONAL_INFO = "additional_info"
+OPENING_ID = "opening_id"
+STUDENT_ID = "student_id"
+ADDITIONAL_INFO = "additional_info"
STATUS_ACCEPTING_APPLICATIONS = "Accepting Applications"
@@ -54,25 +54,27 @@ PLACEMENT = "Placement"
COMPANY_WEBSITE = 'website'
COMPANY_ADDRESS = 'address'
-COMPANY_PHONE_NUMBER = 'phone_number'
-COMPANY_CONTACT_PERSON_NAME = 'contact_person_name'
+PHONE_NUMBER = 'phone_number'
+CONTACT_PERSON_NAME = 'contact_person_name'
-OPENING_DESIGNATION = 'designation'
-OPENING_DESCRIPTION = 'description'
+DESIGNATION = 'designation'
+DESCRIPTION = 'description'
OPENING_TYPE = 'opening_type'
-OPENING_CITY = 'city'
-OPENING_CITY_TYPE = 'city_type'
-OPENING_COMPENSATION = 'compensation'
-OPENING_COMPENSATION_DETAILS = 'compensation_details'
-OPENING_ALLOWED_BATCH = 'allowed_batch'
-OPENING_ALLOWED_BRANCH = 'allowed_branch'
-OPENING_ATTACHMENTS = 'attachments'
-OPENING_ROUNDS = 'rounds'
-OPENING_ADDITIONAL_INFO = 'additional_info'
-OPENING_ROUND_DETAILS = 'round_details'
-OPENING_DURATION = 'duration'
-OPENING_CO_OP = 'co_op'
-OPENING_START_DATE = 'start_date'
+CITY = 'city'
+CITY_TYPE = 'city_type'
+COMPENSATION = 'compensation'
+COMPENSATION_DETAILS = 'compensation_details'
+ALLOWED_BATCH = 'allowed_batch'
+ALLOWED_BRANCH = 'allowed_branch'
+ATTACHMENTS = 'attachments'
+ROUNDS = 'rounds'
+ROUND_DETAILS = 'round_details'
+DURATION = 'duration'
+CO_OP = 'co_op'
+START_DATE = "start_date"
+
+STUDENT_LIST = "student_list"
+STUDENT_STATUS = "student_status"
BRANCHES = [
"CSE",
@@ -87,6 +89,13 @@ BATCHES = [
]
COMPANY_OPENING_SUBMITTED_TEMPLATE_SUBJECT = "Notification Submitted - {id} - CDC IIT Dharwad"
+STUDENT_APPLICATION_STATUS_TEMPLATE_SUBJECT = 'Application Status : {company_name} - {id}'
+STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT = 'CDC - Application Submitted - {company_name}'
STUDENT_APPLICATION_SUBMITTED_TEMPLATE = 'student_application_submitted.html'
COMPANY_OPENING_SUBMITTED_TEMPLATE = 'company_opening_submitted.html'
+STUDENT_APPLICATION_STATUS_SELECTED_TEMPLATE = 'student_application_status_selected.html'
+STUDENT_APPLICATION_STATUS_NOT_SELECTED_TEMPLATE = 'student_application_status_not_selected.html'
+
+
+
diff --git a/CDC_Backend/APIs/models.py b/CDC_Backend/APIs/models.py
index e844dc2..cd3784d 100644
--- a/CDC_Backend/APIs/models.py
+++ b/CDC_Backend/APIs/models.py
@@ -90,12 +90,13 @@ class PlacementApplication(models.Model):
class Meta:
verbose_name_plural = "Placement Applications"
+ unique_together = ('placement_id', 'student_id')
class PrePlacementOffer(models.Model):
id = models.AutoField(primary_key=True)
student = models.ForeignKey(Student, on_delete=models.CASCADE, blank=False)
- company = models.CharField(max_length=50, blank=False)
+ company = models.CharField(max_length=50, blank=False, default="")
compensation = models.IntegerField(blank=False) # Job - Per Year
compensation_details = models.CharField(blank=True, max_length=200)
tier = models.CharField(blank=False, choices=TIERS, max_length=10)
diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py
index 6abee88..2effcb8 100644
--- a/CDC_Backend/APIs/studentViews.py
+++ b/CDC_Backend/APIs/studentViews.py
@@ -132,18 +132,18 @@ def deleteResume(request, id, email, user_type):
@api_view(['POST'])
@isAuthorized(allowed_users=[STUDENT])
-@precheck(required_data=[APPLICATION_OPENING_TYPE, APPLICATION_OPENING_ID, RESUME_FILE_NAME,
- APPLICATION_ADDITIONAL_INFO])
+@precheck(required_data=[OPENING_TYPE, OPENING_ID, RESUME_FILE_NAME,
+ ADDITIONAL_INFO])
def submitApplication(request, id, email, user_type):
try:
data = request.data
student = get_object_or_404(Student, id=id)
- if data[APPLICATION_OPENING_TYPE] == PLACEMENT:
+ if data[OPENING_TYPE] == PLACEMENT:
if not len(PlacementApplication.objects.filter(
- student_id=id, placement_id=data[APPLICATION_OPENING_ID])):
+ student_id=id, placement_id=data[OPENING_ID])):
application = PlacementApplication()
- opening = get_object_or_404(Placement, id=data[APPLICATION_OPENING_ID],
+ opening = get_object_or_404(Placement, id=data[OPENING_ID],
status=STATUS_ACCEPTING_APPLICATIONS)
cond_stat, cond_msg = PlacementApplicationConditions(student, opening)
print(cond_stat, cond_msg)
@@ -153,7 +153,7 @@ def submitApplication(request, id, email, user_type):
else:
raise PermissionError("Application is already Submitted")
else:
- raise ValueError(APPLICATION_OPENING_TYPE + " is Invalid")
+ raise ValueError(OPENING_TYPE + " is Invalid")
if data[RESUME_FILE_NAME] in student.resumes:
application.resume = data[RESUME_FILE_NAME]
@@ -163,15 +163,19 @@ def submitApplication(request, id, email, user_type):
application.student = student
application.id = generateRandomString()
for i in opening.additional_info:
- if i not in data[APPLICATION_ADDITIONAL_INFO]:
+ if i not in data[ADDITIONAL_INFO]:
print(i)
raise AttributeError(i + " not found in Additional Info")
- application.additional_info = data[APPLICATION_ADDITIONAL_INFO]
- if not sendApplicationEmail(email, student.name, opening.company.name, data[APPLICATION_OPENING_TYPE],
- data[APPLICATION_ADDITIONAL_INFO]):
- logger.error("Submit Application: Unable to Send Email")
- # raise RuntimeError("Unable to Send Email")
+ application.additional_info = data[ADDITIONAL_INFO]
+ data = {
+ "name": student.name,
+ "company_name": opening.company.name,
+ "application_type": data[OPENING_TYPE],
+ "additional_info": data[ADDITIONAL_INFO]
+ }
+ subject = STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT.format(company_name=opening.company.name)
+ sendEmail(email, subject, data, STUDENT_APPLICATION_SUBMITTED_TEMPLATE)
application.save()
return Response({'action': "Submit Application", 'message': "Application Submitted"},
diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py
index 422cec1..e344be4 100644
--- a/CDC_Backend/APIs/utils.py
+++ b/CDC_Backend/APIs/utils.py
@@ -15,6 +15,7 @@ from google.auth.transport import requests
from google.oauth2 import id_token
from rest_framework import status
from rest_framework.response import Response
+import background_task
from .models import *
@@ -108,30 +109,6 @@ def generateRandomString():
return False
-def sendApplicationEmail(email, name, company_name, applicaton_type, additional_info):
- try:
- subject = 'CDC - Application Submitted - ' + str(company_name)
- data = {
- "name": name,
- "company_name": company_name,
- "applicaton_type": applicaton_type,
- "additional_info": additional_info
- }
-
- html_content = render_to_string('student_application_submited.html', data) # render with dynamic value
- text_content = strip_tags(html_content)
-
- email_from = settings.EMAIL_HOST_USER
- recipient_list = [str(email), ]
-
- msg = EmailMultiAlternatives(subject, text_content, email_from, recipient_list)
- msg.attach_alternative(html_content, "text/html")
- msg.send()
- return True
- except:
- return False
-
-
def saveFile(file, location):
prefix = generateRandomString()
file_name = prefix + "_" + file.name
@@ -149,7 +126,7 @@ def saveFile(file, location):
return file_name
-
+@background_task.background(schedule=10)
def sendEmail(email_to, subject, data, template):
try:
html_content = render_to_string(template, data) # render with dynamic value
@@ -163,8 +140,9 @@ def sendEmail(email_to, subject, data, template):
msg.send()
return True
except:
+ logger.error("Send Email: " + str(sys.exc_info()))
print(str(sys.exc_info()[1]))
- return str(sys.exc_info()[1])
+ return False
def PlacementApplicationConditions(student, placement):
diff --git a/CDC_Backend/templates/company_opening_submitted.html b/CDC_Backend/templates/company_opening_submitted.html
new file mode 100644
index 0000000..88147e0
--- /dev/null
+++ b/CDC_Backend/templates/company_opening_submitted.html
@@ -0,0 +1,85 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+ Thank You for filling the form
+
+ 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
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+
+ ® CDC,IIT Dharwad,2021
+
+ |
+
+
+
+
+
+ |
+
+
+ |
+
+
+
+
\ No newline at end of file