Browse Source

downloads and more

kora 1 year ago
parent
commit
89bd689074

+ 6 - 8
app.py

@@ -16,7 +16,7 @@ def main():
     try:
         formFields = getFormFields(confFilePath)
     except:
-        return redirect(url_for('error'))
+        return redirect(url_for('error', message='no valid config file found'))
 
 
     if request.method == 'POST':
@@ -48,11 +48,11 @@ def main():
                 else:
                     raise Exception("No data") 
         except:
-            return redirect(url_for('error'))
+            return redirect(url_for('error', message='no CSV data, or CSV input file missing required data'))
 
-        return redirect(url_for('download', filename=outFileName))
+        return redirect(url_for('main', download=outFileName))
 
-    return render_template('index.html', data=formFields)
+    return render_template('index.html.j2', data=formFields)
 
 
 @app.route('/error/', methods=['POST','GET'])
@@ -60,17 +60,15 @@ def error():
     if request.method == 'POST':
         return redirect(url_for('main'))
     else:
-        return render_template('error.html')
+        return render_template('error.html.j2', message=request.args.get('message'))
 
 
-@app.route('/', methods=['POST', 'GET'])
+@app.route('/download/', 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__':

+ 21 - 21
samples/RDF/form_output.ttl

@@ -9,29 +9,29 @@
 @prefix owl: <http://www.w3.org/2002/07/owl#> .
 @prefix aspo: <http://www.archiviodistato.prato.it/accedi-e-consulta/aspoMV001/scheda/> .
 
-aut:aa rdf:type crm:E21_Person .
-aut:aa rdf:type foaf:person .
-aut:aa foaf:name "" .
-aut:aa foaf:givenName "" .
-aut:aa foaf:gender "" .
-aut:aa rdfs:label ", " .
-aut:aa crm:P3_has_note aut:aa_E62 .
-aut:aa crm:P98i_was_born aut:aa_E67 .
-aut:aa crm:P100i_died_in aut:aa_E69 .
-aut:aa crm:P1_is_identified_by aut: .
-aut:aa schema:hasOccupation mpp: .
-aut:aa_E62 rdf:type crm:E62_String .
-aut:aa_E62 rdfs:label "Fonte: Museo di Palazzo Pretorio - Collezione Martini" .
+aut:sd rdf:type crm:E21_Person .
+aut:sd rdf:type foaf:person .
+aut:sd foaf:name "" .
+aut:sd foaf:givenName "" .
+aut:sd foaf:gender "" .
+aut:sd rdfs:label ", " .
+aut:sd crm:P3_has_note aut:sd_E62 .
+aut:sd crm:P98i_was_born aut:sd_E67 .
+aut:sd crm:P100i_died_in aut:sd_E69 .
+aut:sd crm:P1_is_identified_by aut: .
+aut:sd schema:hasOccupation mpp: .
+aut:sd_E62 rdf:type crm:E62_String .
+aut:sd_E62 rdfs:label "Fonte: Museo di Palazzo Pretorio - Collezione Martini" .
 aut: rdf:type crm:E42_Identifier .
 aut: rdfs:label "" .
-aut:aa_E67 rdf:type crm:E67_Birth .
-aut:aa_E67 rdfs:label "Nascita di " .
-aut:aa_E67 crm:P7_took_place_at mpp: .
-aut:aa_E67 crm:P4_has_time-span mpp: .
-aut:aa_E69 rdf:type crm:E69_Death .
-aut:aa_E69 rdfs:label "Morte di " .
-aut:aa_E69 crm:P7_took_place_at mpp: .
-aut:aa_E69 crm:P4_has_time-span mpp: .
+aut:sd_E67 rdf:type crm:E67_Birth .
+aut:sd_E67 rdfs:label "Nascita di " .
+aut:sd_E67 crm:P7_took_place_at mpp: .
+aut:sd_E67 crm:P4_has_time-span mpp: .
+aut:sd_E69 rdf:type crm:E69_Death .
+aut:sd_E69 rdfs:label "Morte di " .
+aut:sd_E69 crm:P7_took_place_at mpp: .
+aut:sd_E69 crm:P4_has_time-span mpp: .
 mpp: rdf:type crm:E52_Time-Span .
 mpp: rdfs:label "" .
 mpp: rdf:type crm:E53_Place .

+ 0 - 9
templates/error.html

@@ -1,9 +0,0 @@
-<!DOCTYPE html>
-<html>
-<body>
-<form method="POST">
-<b>DATA ERROR:</b> bad config file, no CSV data, or CSV input file missing required data<br/>
-<input type="submit" value="Back">
-</form>
-</body>
-</html>

+ 22 - 0
templates/error.html.j2

@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+  <meta charset="UTF-8">
+  <meta name="viewport" content="width=device-width, initialscale=1.0">
+  <title>IPERION-HS Semantic Data Integrator (task 5.4)</title>
+  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
+  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
+  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
+  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
+</head>
+
+<body>
+  {% include 'main_header.html.j2' %}
+  <form method="POST" style="margin: 2em;  border-style: groove;  padding: 2em;">
+  <b>ERROR:</b> {{message}}<br/>
+  <input type="submit" value="Back">
+  </form>
+</body>
+
+</html>

+ 0 - 76
templates/index.html

@@ -1,76 +0,0 @@
-<!DOCTYPE html>
-<html>
-
-<head>
-  <meta charset="UTF-8">
-  <meta name="viewport" content="width=device-width, initialscale=1.0">
-  <title>IPERION-HS Semantic Data Integrator (task 5.4)</title>
-  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
-  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
-  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
-  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
-</head>
-
-<body>
-
-  <header class="sticky-top">
-		<nav class="navbar navbar-expand-lg navbar-light bg-white">
-			<div class="container-fluid">
-				<div class="navbar-brand">
-					<a href="https://www.iperionhs.eu/"><img src="http://restore.ovi.cnr.it/img/LogoIperion.png" width="200" alt="Iperion" /></a>
-				</div>
-				<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
-					<span class="navbar-toggler-icon"></span>
-				</button>
-				<div class="collapse navbar-collapse justify-content-end" id="navbarNavDropdown">
-					<ul class="navbar-nav">
-						<li class="nav-item">
-							<a class="nav-link" href="https://www.iperionhs.eu/">Iperion</a>
-						</li>
-						<li class="nav-item">
-							<a class="nav-link" href="https://marketplace.sshopencloud.eu/tool-or-service/pIyy0d">Raise</a>
-						</li>
-						<li class="nav-item active">
-							<a class="nav-link" href="#">Demo</a>
-						</li>
-						
-					</ul>
-				</div>
-			</div>
-		</nav>
-	</header>
-
-
-<h1 style="margin-left: 1em">IPERION-HS Semantic Data Integrator (task 5.4)</h1>
-  <form method="POST" enctype = "multipart/form-data" style="margin: 2em;  border-style: groove;  padding: 2em;">
-    <div>
-      Upload a CSV file:
-      <fieldset>
-        <input type="file" id="FILE" name="FILE"><br/><br/>
-      </fieldset>
-      <input id="submitted" type="submit" value="Activate Transformation" >
-    </div>
-    <div>
-        <br/>... or manually enter the data of a record:<br/><br/>
-      <fieldset>
-        <legend>Record:</legend>
-        {% for entry in data: %}
-          <label for="nome">{{entry}}</label><br>
-          <input type="text" id="{{entry}}" name="{{entry}}" placeholder="data"><br><br>
-        {% endfor %}
-      </fieldset>
-    </div>
-  </form>
-
-<p>When you activate this tool, input data is translated into RDF (TTL) via a user-customizable model</p>
-<script>
-  const params = new URLSearchParams(window.location.search);
-  console.log('stoca', window.location.search);
-  console.log('zo', params);
-  console.log('z', params.get('success'));
-  if(params.get('success')){
-    alert("Transformation carried out successfully");
-  }
- </script>
-</body>
-</html>

+ 56 - 0
templates/index.html.j2

@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+  <meta charset="UTF-8">
+  <meta name="viewport" content="width=device-width, initialscale=1.0">
+  <title>IPERION-HS Semantic Data Integrator (task 5.4)</title>
+  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
+  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
+  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
+  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
+</head>
+
+<body>
+
+  {% include 'main_header.html.j2' %}
+
+  <form id="fileForm" method="POST" enctype = "multipart/form-data" style="margin: 2em;  border-style: groove;  padding: 2em;">
+    <div>
+      Upload a CSV file:
+      <fieldset>
+        <input type="file" id="FILE" name="FILE"><br/><br/>
+      </fieldset>
+      <input id="submitted" type="submit" value="Activate Transformation" >
+    </div>
+    <div>
+        <br/>... or manually enter the data of a record:<br/><br/>
+      <fieldset>
+        <legend>Record:</legend>
+        {% for entry in data: %}
+          <label for="nome">{{entry}}</label><br>
+          <input type="text" id="{{entry}}" name="{{entry}}" placeholder="data"><br><br>
+        {% endfor %}
+      </fieldset>
+    </div>
+  </form>
+
+  <script>
+    const params = new URLSearchParams(window.location.search);
+    const downloadName = params.get('download');
+    if(downloadName){
+      document.getElementById("fileForm").reset()
+      $.get('/download', { filename: downloadName }).done(function(data){
+        let link = document.createElement('a');
+        link.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(data);
+        link.download = downloadName;
+        link.click();
+      }
+    );
+      alert("Transformation carried out successfully");
+    }
+  </script>
+
+</body>
+
+</html>

+ 29 - 0
templates/main_header.html.j2

@@ -0,0 +1,29 @@
+  <header class="sticky-top">
+		<nav class="navbar navbar-expand-lg navbar-light bg-white">
+			<div class="container-fluid">
+				<div class="navbar-brand">
+					<a href="https://www.iperionhs.eu/"><img src="http://restore.ovi.cnr.it/img/LogoIperion.png" width="200" alt="Iperion" /></a>
+				</div>
+				<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
+					<span class="navbar-toggler-icon"></span>
+				</button>
+				<div class="collapse navbar-collapse justify-content-end" id="navbarNavDropdown">
+					<ul class="navbar-nav">
+						<li class="nav-item">
+							<a class="nav-link" href="https://www.iperionhs.eu/">Iperion</a>
+						</li>
+						<li class="nav-item">
+							<a class="nav-link" href="https://marketplace.sshopencloud.eu/tool-or-service/pIyy0d">Raise</a>
+						</li>
+						<li class="nav-item active">
+							<a class="nav-link" href="#">Demo</a>
+						</li>
+						
+					</ul>
+				</div>
+			</div>
+		</nav>
+	</header>
+
+  <h1 style="margin-left: 2rem">IPERION-HS Semantic Data Integrator (task 5.4)</h1>
+  <p style="margin-left: 2rem">When you activate this tool, input data is translated into RDF (TTL) via a user-customizable model</p>

+ 0 - 10
templates/provina.html

@@ -1,10 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<h1>File upload button example</h1>
-<p>Click on the "Choose File" button to upload a file:</p>
-<form>
-<input type="file" id="FILE" name="filename">
-</form>
-</body>
-</html>