From 32c6468ade0fee24e3c6ee176515ea2d8d3bb937 Mon Sep 17 00:00:00 2001 From: Gowtham Sai <66207607+gowtham3105@users.noreply.github.com> Date: Fri, 17 Dec 2021 19:23:32 +0530 Subject: [PATCH] Fixed Bugs --- CDC_Backend/APIs/adminViews.py | 46 +++++++++++++++++--------------- CDC_Backend/APIs/companyViews.py | 7 +++-- CDC_Backend/APIs/utils.py | 2 +- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index dc50652..014d79c 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -1,10 +1,10 @@ -import json -from datetime import datetime - -from .utils import * -from rest_framework.decorators import api_view import csv +import json + +from rest_framework.decorators import api_view + from .serializers import * +from .utils import * @api_view(['POST']) @@ -22,8 +22,9 @@ def markStatus(request, id, email, user_type): application.selected = True if i[STUDENT_SELECTED] == "true" else False email = str(application.student.roll_no) + "@iitdh.ac.in" # Only allowing for IITDh emails - subject = STUDENT_APPLICATION_STATUS_TEMPLATE_SUBJECT.format(company_name=application.placement.company_name, - id=application.id) + subject = STUDENT_APPLICATION_STATUS_TEMPLATE_SUBJECT.format( + company_name=application.placement.company_name, + id=application.id) data = { "company_name": application.placement.company_name, "designation": application.placement.designation, @@ -53,15 +54,17 @@ def markStatus(request, id, email, user_type): def getDashboard(request, id, email, user_type): try: placements = Placement.objects.all().order_by('-created_at') - ongoing = placements.filter(deadline_datetime__gt=datetime.now(), offer_accepted__isnull=False) - previous = placements.exclude(deadline_datetime__gt=datetime.now()).filter(offer_accepted__isnull=False) + ongoing = placements.filter(deadline_datetime__gt=datetime.datetime.now(), offer_accepted__isnull=False) + previous = placements.exclude(deadline_datetime__gt=datetime.datetime.now()).filter( + offer_accepted__isnull=False) new = placements.filter(offer_accepted__isnull=True) ongoing = PlacementSerializerForAdmin(ongoing, many=True).data previous = PlacementSerializerForAdmin(previous, many=True).data new = PlacementSerializerForAdmin(new, many=True).data return Response( - {'action': "Get Dashboard - Admin", 'message': "Data Found", "ongoing": ongoing, "previous": previous, "new": new}, + {'action': "Get Dashboard - Admin", 'message': "Data Found", "ongoing": ongoing, "previous": previous, + "new": new}, status=status.HTTP_200_OK) except Http404: return Response({'action': "Get Dashboard - Admin", 'message': 'Student Not Found'}, @@ -80,7 +83,7 @@ def updateDeadline(request, id, email, user_type): data = request.data opening = get_object_or_404(Placement, pk=data[OPENING_ID]) # Updating deadline date with correct format in datetime field - opening.deadline_datetime = datetime.strptime(data[DEADLINE_DATETIME], '%Y-%m-%d %H:%M:%S %z') + opening.deadline_datetime = datetime.datetime.strptime(data[DEADLINE_DATETIME], '%Y-%m-%d %H:%M:%S %z') opening.save() return Response({'action': "Update Deadline", 'message': "Deadline Updated"}, status=status.HTTP_200_OK) @@ -92,6 +95,7 @@ def updateDeadline(request, id, email, user_type): return Response({'action': "Update Deadline", 'message': "Something went wrong"}, status=status.HTTP_400_BAD_REQUEST) + @api_view(['POST']) @isAuthorized([ADMIN]) @precheck([OPENING_ID, OFFER_ACCEPTED]) @@ -111,6 +115,7 @@ def updateOfferAccepted(request, id, email, user_type): return Response({'action': "Update Offer Accepted", 'message': "Something went wrong"}, status=status.HTTP_400_BAD_REQUEST) + @api_view(['POST']) @isAuthorized([ADMIN]) @precheck([OPENING_ID, EMAIL_VERIFIED]) @@ -130,6 +135,7 @@ def updateEmailVerified(request, id, email, user_type): return Response({'action': "Update Email Verified", 'message': "Something went wrong"}, status=status.HTTP_400_BAD_REQUEST) + @api_view(['POST']) @isAuthorized([ADMIN]) @precheck([OPENING_ID, ADDITIONAL_INFO]) @@ -167,8 +173,8 @@ def getApplications(request, id, email, user_type): opening = get_object_or_404(Placement, pk=data[OPENING_ID]) applications = PlacementApplication.objects.filter(placement=opening) serializer = PlacementApplicationSerializerForAdmin(applications, many=True) - return Response({'action': "Get Applications", 'message': 'Data Found', 'applications':serializer.data}, - status=status.HTTP_200_OK) + return Response({'action': "Get Applications", 'message': 'Data Found', 'applications': serializer.data}, + status=status.HTTP_200_OK) except Http404: return Response({'action': "Get Applications", 'message': 'Opening Not Found'}, status=status.HTTP_404_NOT_FOUND) @@ -178,7 +184,6 @@ def getApplications(request, id, email, user_type): status=status.HTTP_400_BAD_REQUEST) - @api_view(['POST']) @isAuthorized(allowed_users=[ADMIN]) @precheck(required_data=[OPENING_TYPE, OPENING_ID, RESUME_FILE_NAME, @@ -195,7 +200,7 @@ def submitApplication(request, id, email, user_type): opening = get_object_or_404(Placement, id=data[OPENING_ID], allowed_batch__contains=[student.batch], allowed_branch__contains=[student.branch], - deadline_datetime__gte=datetime.now().date() + deadline_datetime__gte=datetime.datetime.now().date() ) if not opening.offer_accepted or not opening.email_verified: raise PermissionError("Placement Not Approved") @@ -231,7 +236,7 @@ def submitApplication(request, id, email, user_type): "additional_info": dict(json.loads(application.additional_info)), } subject = STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT.format(company_name=opening.company_name) - student_email = str(student.roll_no)+"@iitdh.ac.in" + student_email = str(student.roll_no) + "@iitdh.ac.in" sendEmail(student_email, subject, data, STUDENT_APPLICATION_SUBMITTED_TEMPLATE) application.save() @@ -252,7 +257,6 @@ def submitApplication(request, id, email, user_type): status=status.HTTP_400_BAD_REQUEST) - @api_view(['POST']) @isAuthorized(allowed_users=[ADMIN]) @precheck(required_data=[OPENING_ID]) @@ -272,12 +276,12 @@ def generateCSV(request, id, email, user_type): header_row.extend(placement.additional_info) writer.writerow(header_row) for apl in applications: - row_details=[] + row_details = [] row_details.append(apl.applied_at) row_details.append(apl.student.roll_no) row_details.append(apl.student.name) - row_details.append(str(apl.student.roll_no)+"@iitdh.ac.in") + row_details.append(str(apl.student.roll_no) + "@iitdh.ac.in") row_details.append(apl.student.phone_number) row_details.append(apl.student.branch) row_details.append(apl.student.batch) @@ -291,11 +295,11 @@ def generateCSV(request, id, email, user_type): writer.writerow(row_details) f.close() - file_path = LINK_TO_APPLICATIONS_CSV + urllib.parse.quote_plus(filename+".csv") + file_path = LINK_TO_APPLICATIONS_CSV + urllib.parse.quote_plus(filename + ".csv") return Response({'action': "Create csv", 'message': "CSV created", 'file': file_path}, status=status.HTTP_200_OK) except: logger.warning("Create csv: " + str(sys.exc_info())) print(sys.exc_info()) return Response({'action': "Create csv", 'message': "Error Occurred"}, - status=status.HTTP_400_BAD_REQUEST) \ No newline at end of file + status=status.HTTP_400_BAD_REQUEST) diff --git a/CDC_Backend/APIs/companyViews.py b/CDC_Backend/APIs/companyViews.py index 862483f..b133b81 100644 --- a/CDC_Backend/APIs/companyViews.py +++ b/CDC_Backend/APIs/companyViews.py @@ -1,5 +1,4 @@ import json -import datetime from rest_framework.decorators import api_view @@ -178,7 +177,8 @@ def addPlacement(request): else: raise ValueError('Invalid compensation gross') # Convert to date object - opening.tentative_date_of_joining = datetime.datetime.strptime(data[TENTATIVE_DATE_OF_JOINING], '%d-%m-%Y').date() + opening.tentative_date_of_joining = datetime.datetime.strptime(data[TENTATIVE_DATE_OF_JOINING], + '%d-%m-%Y').date() # Only Allowing Fourth Year for Placement opening.allowed_batch = [FOURTH_YEAR, ] @@ -202,8 +202,6 @@ def addPlacement(request): opening.save() - - stat, link = generateOneTimeVerificationLink(opening.email, opening.id, "Placement") if not stat: raise RuntimeError("Error in generating one time verification link for placement") @@ -226,6 +224,7 @@ def addPlacement(request): return Response({'action': "Add Placement", 'message': "Something went wrong"}, status=status.HTTP_400_BAD_REQUEST) + @api_view(['POST']) @precheck([TOKEN]) def verifyEmail(request): diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index 382e995..d00e35c 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -5,10 +5,10 @@ import random import re import string import sys -import jwt from os import path, remove import background_task +import jwt from django.conf import settings from django.core.mail import EmailMultiAlternatives from django.http import Http404