1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| def launchCtd(request):
"""
This Function is activate when user click on the launch button of the convertToDose page.
It receive the request, create the JSON file and launch the ConvertToDose Analysis. Then it redirect to the Result page
"""
if request.method == 'POST':
#2 => page 2 après recharge des donnees
if bool(request.FILES.get('calibrationFile', False)) == True and bool(request.FILES.get('imgFile', False)) == True :
analyseType = request.POST.get("analyse_type")
img_file_name = handle_uploaded_file(request.FILES['imgFile'],
request.POST.get("protocol_name"), 'dataset_ctd', 'converttodose')
calibration_file_name = handle_uploaded_file(request.FILES['calibrationFile'],
request.POST.get("protocol_name"), 'converttodose')
formJsonFile = JsonFileForm(request.POST, request.FILES)
formImgFile = ImgFileForm(request.POST, request.FILES)
formCtd = CtdForm()
formCtd.fields["protocol_name"].initial = request.POST.get("protocol_name")
formCtd.fields["analyse_type"].initial = analyseType
pathAnalyseForm = PathAnalyseForm()
pathAnalyseForm.fields["img_path"].initial = img_file_name
pathAnalyseForm.fields["json_path"].initial = calibration_file_name
if analyseType == 'rb':
factorsCalib = ExtractDataJson(calibration_file_name, "convertToDose", analyseType)
context = {
'factors': True,
'factorsCalib': factorsCalib,
'formCtd': formCtd,
'formJsonFile': formJsonFile,
'formImgFile': formImgFile,
'pathAnalyseForm': pathAnalyseForm,
'maxDose': 950,
}
return render(request, 'convertToDose.html', context)
elif analyseType == 'multi':
factorsCalib, doseRect, ctrlRect = ExtractDataJson(calibration_file_name, "convertToDose", analyseType)
context = {
'factors': True,
'factorsCalib': factorsCalib,
'formCtd': formCtd,
'formJsonFile': formJsonFile,
'formImgFile': formImgFile,
'pathAnalyseForm': pathAnalyseForm,
'doseRect': doseRect,
'ctrlRect': ctrlRect,
}
return render(request, 'convertToDose.html', context)
else: #3 => envoie page resultat
if request.is_ajax:
print ("here")
img_path = request.POST.get("img_path")
json_pactrlRectth = request.POST.get("json_path")
method = request.POST.get("analyse_type")
protocole_name = request.POST.get("protocol_name")
if method == 'rb':
maxDose = request.POST.get("maxDose")
doseRect = []
ctrlRect = []
if method == 'multi':
maxDose = 0
#doseRectStr = request.POST.get("arrayDoseRect") => impossible... get comme getlist et je n'ai rien avec ce nom dans le debeugger
#doseRect = list(map(int,doseRectStr.split(",")))
#ctrlRectStr = request.POST.getlist("arrayCtrlRect[]")
#print(ctrlRectStr)
#ctrlRect = list(map(int,ctrlRectStr.split(",")))
doseRect = []
ctrlRect = []
UpdateDataJson(json_pactrlRectth, method, doseRect, ctrlRect)
if request.POST.get("fingerprint") == 'on':
fingerprint = True
else:
fingerprint = False
img_out_path = "test"
#img_out_path = execute(json_pactrlRectth,img_path,method, protocole_name, maxDose, fingerprint, doseRect, ctrlRect)
context = {
'filename': img_out_path,
'protocol_file': json_pactrlRectth,
}
return render(request, 'result.html', context)
#return JsonResponse(context, safe=False)
#1 => page initiale
else:
formCtd = CtdForm()
formJsonFile = JsonFileForm()
formImgFile = ImgFileForm()
context = {
'factors': False,
'formCtd': formCtd,
'formJsonFile': formJsonFile,
'formImgFile' : formImgFile,
}
return render(request, 'convertToDose.html', context) |
Partager