|
@@ -1,4 +1,4 @@
|
|
-from flask import Flask, request, redirect, render_template
|
|
|
|
|
|
+from flask import Flask, request, redirect, render_template, url_for
|
|
from parsers.CSV_to_RDF_generico import parse, parsefromfile
|
|
from parsers.CSV_to_RDF_generico import parse, parsefromfile
|
|
from parsers.get_form_fields import getFormFields
|
|
from parsers.get_form_fields import getFormFields
|
|
|
|
|
|
@@ -8,14 +8,15 @@ app = Flask(__name__)
|
|
@app.route('/', methods=['POST','GET'])
|
|
@app.route('/', methods=['POST','GET'])
|
|
def main():
|
|
def main():
|
|
|
|
|
|
|
|
+ appath = app.root_path + '/'
|
|
configurationFolder = 'parsers/configuration_files/'
|
|
configurationFolder = 'parsers/configuration_files/'
|
|
configurationFileName = 'configuration.json'
|
|
configurationFileName = 'configuration.json'
|
|
- confFilePath = configurationFolder + configurationFileName
|
|
|
|
|
|
+ confFilePath = appath + configurationFolder + configurationFileName
|
|
|
|
|
|
try:
|
|
try:
|
|
formFields = getFormFields(confFilePath)
|
|
formFields = getFormFields(confFilePath)
|
|
except:
|
|
except:
|
|
- return redirect('/error/')
|
|
|
|
|
|
+ return redirect(url_for('error'))
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
if request.method == 'POST':
|
|
@@ -27,7 +28,7 @@ def main():
|
|
|
|
|
|
if filename != '':
|
|
if filename != '':
|
|
outFileName = fileFromRequest.filename.replace('.csv', '') + '.ttl'
|
|
outFileName = fileFromRequest.filename.replace('.csv', '') + '.ttl'
|
|
- outFilePath = outputFolder+outFileName
|
|
|
|
|
|
+ outFilePath = appath + outputFolder + outFileName
|
|
inFile = fileFromRequest.read()
|
|
inFile = fileFromRequest.read()
|
|
# try to create list of dictionaries keyed by header row
|
|
# try to create list of dictionaries keyed by header row
|
|
parsefromfile(confFilePath, formFields, inFile, outFilePath)
|
|
parsefromfile(confFilePath, formFields, inFile, outFilePath)
|
|
@@ -41,11 +42,12 @@ def main():
|
|
check = [val for val in data.values() if val!='']
|
|
check = [val for val in data.values() if val!='']
|
|
|
|
|
|
if len(check)>0:
|
|
if len(check)>0:
|
|
- parse(confFilePath, formFields,[data], outputFolder + 'form_output.ttl')
|
|
|
|
|
|
+ outFilePath = appath + outputFolder + 'form_output.ttl'
|
|
|
|
+ parse(confFilePath, formFields,[data], outFilePath)
|
|
else:
|
|
else:
|
|
- return redirect('/error/')
|
|
|
|
|
|
+ return redirect(url_for('error'))
|
|
|
|
|
|
- return redirect('/')
|
|
|
|
|
|
+ return redirect(url_for('main'))
|
|
|
|
|
|
return render_template('index.html', data=formFields)
|
|
return render_template('index.html', data=formFields)
|
|
|
|
|
|
@@ -53,7 +55,7 @@ def main():
|
|
@app.route('/error/', methods=['POST','GET'])
|
|
@app.route('/error/', methods=['POST','GET'])
|
|
def error():
|
|
def error():
|
|
if request.method == 'POST':
|
|
if request.method == 'POST':
|
|
- return redirect('/')
|
|
|
|
|
|
+ return redirect(url_for('main'))
|
|
else:
|
|
else:
|
|
return render_template('error.html')
|
|
return render_template('error.html')
|
|
|
|
|