def uploadCSV(request): print "Inside the upload function" if request.FILES: csvFile = request.FILES['file'] fileName = str(csvFile.name) rowContent = "" if "author.csv" in fileName: rowContent = getAuthorInfo(csvFile) elif "score.csv" in fileName: rowContent = getReviewScoreInfo(csvFile) elif "review.csv" in fileName: rowContent = getReviewInfo(csvFile) elif "submission.csv" in fileName: rowContent = getSubmissionInfo(csvFile) else: rowContent = returnTestChartData(csvFile) print((type(csvFile.name))) if request.POST: # current problem: request from axios not recognized as POST # csvFile = request.FILES['file'] print("Now we got the csv file") return HttpResponse(json.dumps(rowContent)) # return HttpResponse("Got the CSV file.") else: print("Not found the file!") return HttpResponseNotFound('Page not found for CSV')
def uploadCSV(request): print("Inside the upload function") if request.FILES: # print("Check : ", request.FILES.getlist('file')) # csvFile = request.FILES['file'] # print("checkrequest : ", csvFiles) listOfFiles = request.FILES.getlist('file') print("How many files : ", len(listOfFiles)) rowContent = "" #Handles single file upload if len(listOfFiles) == 1: print "Inside single File" csvFile = listOfFiles[0] fileName = str(csvFile.name) print("check file name : ", fileName) print("CheckCSVFile : ", type(csvFile)) if "author.csv" in fileName: rowContent = getAuthorInfo(csvFile) elif "score.csv" in fileName: rowContent = getReviewScoreInfo(csvFile) elif "review.csv" in fileName: rowContent = getReviewInfo(csvFile) elif "submission.csv" in fileName: rowContent = getSubmissionInfo(csvFile) else: #rowContent = returnTestChartData(csvFile) # return null? rowContent = invalidFiles() else: # Multi file upload fileNameList = [] for csvFile in listOfFiles: fileNameList.append(str(csvFile.name)) if len( listOfFiles ) == 2 and "author.csv" in fileNameList and "submission.csv" in fileNameList: rowContent = getAuthorAndSubmissionInfo(listOfFiles) elif len( listOfFiles ) == 2 and "author.csv" in fileNameList and "review.csv" in fileNameList: rowContent = getAuthorAndReviewInfo(listOfFiles) else: rowContent = invalidFiles() # print(type(csvFile.name)) if request.POST: # current problem: request from axios not recognized as POST # csvFile = request.FILES['file'] print("Now we got the csv file") print("returnedRow: ", rowContent) return HttpResponse(json.dumps(rowContent)) # return HttpResponse("Got the CSV file.") else: print("Not found the file!") return HttpResponseNotFound('Page not found for CSV')
def uploadCSV(request): print "Inside the upload function" # handling a single file, original code if len(request.FILES.getlist('file')) == 1: csvFile = request.FILES['file'] fileName = str(csvFile.name) rowContent = "" if "author.csv" in fileName: rowContent = getAuthorInfo(csvFile) elif "score.csv" in fileName: rowContent = getReviewScoreInfo(csvFile) elif "review.csv" in fileName: rowContent = getReviewInfo(csvFile) elif "submission.csv" in fileName: rowContent = getSubmissionInfo(csvFile) else: rowContent = returnTestChartData(csvFile) print type(csvFile.name) if request.POST: # current problem: request from axios not recognized as POST # csvFile = request.FILES['file'] print "Now we got the csv file" return HttpResponse(json.dumps(rowContent)) # return HttpResponse("Got the CSV file.") # handling multiple files elif len(request.FILES.getlist('file')) > 1: rowContent = "" #print request.FILES.getlist('file') rowContent = getMultipleFilesInfo(request.FILES.getlist('file')) return HttpResponse(json.dumps(rowContent)) else: print "Not found the file!" return HttpResponseNotFound('Page not found for CSV')
def handle_upload(request): if 'username' not in request: return {'result': False, 'message': 'Missing username'} username = request['username'] if 'mapping' not in request: return {'result': False, 'message': 'Missing mapping'} mapping = request['mapping'].split(',') if request['file']: csvFile = request['file']['file'] fileName = str(csvFile.name) rowContent = "" if "author.csv" in fileName: rowContent = getAuthorInfo(username, mapping, csvFile) elif "score.csv" in fileName: rowContent = getReviewScoreInfo(csvFile) elif "review.csv" in fileName: rowContent = getReviewInfo(username, mapping, csvFile) elif "submission.csv" in fileName: rowContent = getSubmissionInfo(username, mapping, csvFile) else: rowContent = returnTestChartData(csvFile) print type(csvFile.name) if request: # current problem: request from axios not recognized as POST # csvFile = request.FILES['file'] print "Now we got the csv file" return rowContent # return HttpResponse("Got the CSV file.") else: print "Not found the file!" return {'result': False, 'message': 'Page not found for CSV'}