Browse Source

prende_forma

Francesco 1 year ago
parent
commit
e8bacae3db
2 changed files with 18 additions and 4 deletions
  1. 1 1
      .gitignore
  2. 17 3
      app.py

+ 1 - 1
.gitignore

@@ -3,7 +3,7 @@ fvenv/
 venv/
 # Additional Python stuff
 __pycache__/
-**/__pycache__/
+parsers/__pycache__/*
 app.log
 # Output Folder
 samples/RDF/

+ 17 - 3
app.py

@@ -1,4 +1,4 @@
-from flask import Flask, request, redirect, render_template, url_for
+from flask import Flask, request, redirect, render_template, url_for, send_file
 from parsers.CSV_to_RDF_generico import parse, parsefromfile
 from parsers.get_form_fields import getFormFields
 
@@ -42,14 +42,15 @@ def main():
 
                 check = [val for val in data.values() if val!='']
                 if len(check)>0:
-                    outFilePath = outputFolder + 'form_output.ttl'
+                    outFileName = 'form_output.ttl'
+                    outFilePath = outputFolder + outFileName
                     parse(confFilePath, formFields, [data], outFilePath)
                 else:
                     raise Exception("No data") 
         except:
             return redirect(url_for('error'))
 
-        return redirect(url_for('main', success=True))
+        return redirect(url_for('download', filename=outFileName))
 
     return render_template('index.html', data=formFields)
 
@@ -62,5 +63,18 @@ def error():
         return render_template('error.html')
 
 
+@app.route('/', methods=['POST', 'GET'])
+def download():
+    appath = app.root_path + '/'
+    outFileName = request.args.get('filename')
+    outFilePath = appath + 'samples/RDF/' + outFileName
+    return send_file(outFilePath, as_attachment=True)
+#    return redirect(url_for('main', success=True))
+
+
+
 if __name__ == '__main__':
     app.run()
+
+
+