def upload(): """ Retrieving the file from the request object """ # creation of the folder on disk and upload the file selected target=os.path.join(APP_ROOT,"upload") if not os.path.isdir(target): os.mkdir(target) try : file=request.files["InputFile"] filename=file.filename destination="/".join((target,filename)) file.save(destination) myTable=request.form["inputTable"] recImported=0 # Management of the scripts if myTable=="Script" : with open(destination,"r") as f: for line in f: # Init the variables for the process fields=[] fields=line.split(",") # Retrieving the values of the fields if len(fields)== 5 : myScript=Script() myScript.scriptname=fields[0] myScript.scriptdescription=fields[1] myScript.scripttechnology=fields[2] myScript.businessowner=fields[3] myScript.executionfrequency=fields[4] myScript.save() recImported+=1 flash('Congratulations, {} Script(s) records have been imported recently !!! '.format(recImported), 'message') # Management of the scripts if myTable=="Application" : with open(destination,"r") as f: for line in f: # Init the variables for the process fields=[] fields=line.split(",") # Retrieving the values of the fields if len(fields)== 8 : myApplication=Application() myApplication.systemname=fields[0] myApplication.systemdescription=fields[1] myApplication.systemtechnology=fields[2] myApplication.systemprovider=fields[3] myApplication.systemowner=fields[4] myApplication.systemstatus=fields[5] myApplication.systemurl=fields[6] myApplication.systemcategory=fields[7] myApplication.save() recImported+=1 flash('Congratulations, {} Application(s) records have been imported recently !!! '.format(recImported), 'message') # Management of the scripts if myTable=="Contract" : with open(destination,"r") as f: for line in f: # Init the variables for the process fields=[] fields=line.split(",") # Retrieving the values of the fields if len(fields)== 8 : myContract=Contract() myContract.contractref=fields[0] myContract.systemname=fields[1] myContract.contractrenewtype=fields[2] myContract.contractcost=fields[3] myContract.contractstartingdate=fields[4] myContract.contractendingdate=fields[5] myContract.contractcomment=fields[6] mystring=fields[7] mystring=mystring[:-2] myContract.contractyear=int(mystring) myContract.save() recImported+=1 flash('Congratulations, {} Contract(s) records have been imported recently !!! '.format(recImported), 'message') except: flash('Sorry, check the inputs of the importation process !!! ', 'error') return redirect(url_for('menu')) return redirect(url_for('menu'))