www-data před 2 roky
rodič
revize
f4581da350
2 změnil soubory, kde provedl 11 přidání a 9 odebrání
  1. 1 1
      .gitignore
  2. 10 8
      app.py

+ 1 - 1
.gitignore

@@ -1,4 +1,4 @@
 fvenv/*
 __pycache__
 venv/*
-
+.vscode/*

+ 10 - 8
app.py

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