Francesco преди 2 години
родител
ревизия
4282176b6f
променени са 2 файла, в които са добавени 11 реда и са изтрити 8 реда
  1. 1 0
      .gitignore
  2. 10 8
      app.py

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 fvenv/*
 __pycache__
+.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')