45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
from django.shortcuts import render,redirect
|
|
from .models import PlacementApplication
|
|
from django.http import HttpResponse
|
|
from .utils import *
|
|
|
|
import csv
|
|
|
|
@api_view(['POST'])
|
|
@isAuthorized(allowed_users=[ADMIN])
|
|
@precheck(required_data=[COL_NAMES, OPENING_ID])
|
|
def generateCSV(request, id, email, user_type):
|
|
try:
|
|
data = request.data
|
|
applications=PlacementApplication.objects.filter(placement_id = data[OPENING_ID])
|
|
filename = generateRandomString()
|
|
destination_path = STORAGE_DESTINATION_APPLICATION_CSV + filename
|
|
f = open(destination_path, 'w')
|
|
writer = csv.writer(f)
|
|
writer.writerow(COL_NAMES)
|
|
for apl in applications:
|
|
row_details=[]
|
|
for col in COL_NAMES:
|
|
if col == ROLL_NO:
|
|
row_details.append(apl.student.roll_no)
|
|
if col == NAME:
|
|
row_details.append(apl.student.name)
|
|
if col == BATCH:
|
|
row_details.append(apl.student.batch)
|
|
if col == BRANCH:
|
|
row_details.append(apl.student.branch)
|
|
if col == PHONE_NUMBER:
|
|
row_details.append(apl.student.phone_number)
|
|
if col == CPI:
|
|
row_details.append(apl.student.cpi)
|
|
if col == RESUME:
|
|
row_details.append(apl.student.resume)
|
|
writer.writerow(apl)
|
|
f.close()
|
|
return Response({'action': "Create csv", 'message': "CSV created", 'file': filename},
|
|
status=status.HTTP_200_OK)
|
|
except:
|
|
logger.warning("Create csv: " + str(sys.exc_info()))
|
|
return Response({'action': "Create csv", 'message': "Error Occurred"},
|
|
status=status.HTTP_400_BAD_REQUEST)
|