def create_script(request): request_content = json.loads(request.body) script = Script() script.name = request_content["name"] script.resouce = request_content["source"] script.category = request_content["category"] script.content = request_content["content"] script.remark = request_content["remark"] script.version = 1 script.created_by = request.user.username script.save() return render_json({"result": True, "message": "ok"})
def createScript(): """ Script creation """ try: if "username" in session: if request.method == 'POST': myScript = Script( scriptname=request.form["inputScriptName"], scriptdescription=request.form["inputScriptDescription"], scripttechnology=request.form["inputScriptTechnology"], businessowner=request.form["inputBusinessOwner"], executionfrequency=request.form["inputExecutionFrequency"]) myScript.save() flash('Script saved !!! ', 'message') return redirect(url_for('listeScript')) if request.method == 'GET': return render_template('createscript.html') else: flash('Unknown user !!! ', 'error') return render_template('login.html') except: return redirect(url_for('appError'))
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'))