From 20f9ea9141f77b3c21232efc30202408d535de18 Mon Sep 17 00:00:00 2001
From: Dat Nguyen
Date: Thu, 21 Nov 2019 13:45:20 -0600
Subject: working web stuff with running page
---
Web/Server/Results/results.txt | 2 +-
Web/Server/Server.py | 30 ++++++++++++++++------------
Web/Server/static/Server.js | 5 +++++
Web/Server/templates/index.html | 43 ++++++++++++++++++++++++++++++++++++++++
Web/Server/templates/upload.html | 37 ----------------------------------
5 files changed, 66 insertions(+), 51 deletions(-)
create mode 100644 Web/Server/templates/index.html
delete mode 100644 Web/Server/templates/upload.html
(limited to 'Web/Server')
diff --git a/Web/Server/Results/results.txt b/Web/Server/Results/results.txt
index ce8f671..f668b82 100644
--- a/Web/Server/Results/results.txt
+++ b/Web/Server/Results/results.txt
@@ -1,2 +1,2 @@
THIS IS RESULTS TEXT
-Current Time = 21:07:34
\ No newline at end of file
+Current Time = 13:41:59
\ No newline at end of file
diff --git a/Web/Server/Server.py b/Web/Server/Server.py
index bab440a..0c3013b 100644
--- a/Web/Server/Server.py
+++ b/Web/Server/Server.py
@@ -9,10 +9,10 @@ import requests
import json
app = Flask(__name__)
-app.secret_key = "secret key"
+app.secret_key = "ski u mah"
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
-ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'py'])
+ALLOWED_EXTENSIONS = set(['py'])
PI_URL = 'http://localhost:8000'
@@ -22,8 +22,8 @@ def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/')
-def upload_form():
- return render_template('upload.html')
+def home():
+ return render_template('index.html')
@app.route('/upload', methods=['POST'])
def upload_file():
@@ -41,30 +41,34 @@ def upload_file():
# Send the file content as a post to the PI
if file and allowed_file(file.filename):
- dictToSend = {'file_content':file.read()}
+ dictToSend = {'filename':file.filename, 'file_content':file.read()}
file.close
print('Running test')
flash('Running test')
response = requests.post(PI_URL + '/tests/endpoint', json=dictToSend)
- contents = json.loads(response.text)[u'results_content']
- flash('Response from server:' + contents)
-
+
+ results_filename = json.loads(response.text)[u'results_filename'] .encode("ascii")
+ results_content = json.loads(response.text)[u'results_content'].encode("ascii")
+ flash('Results file:' + results_filename)
+ flash('Response from server:' + results_content)
+
results = open(RESULTS_DESTINATION, "w")
- results.write(contents)
+ results.write(results_content)
results.close()
- return render_template('upload.html', results = 'True')
+ return render_template('index.html', results = 'True')
else:
flash('Allowed file types are txt, pdf, png, jpg, jpeg, gif')
return redirect(request.url)
-@app.route('/results', methods=['GET'])# this is a job for GET, not POST
+@app.route('/results', methods=['GET'])
def download():
- print("in downlaods")
+ # Grab content from results file
with open(RESULTS_DESTINATION, 'r') as results:
results_content = results.read()
results.close()
- print("results_content")
+
+ # Put content as a download file
return Response(
results_content,
mimetype="text/csv",
diff --git a/Web/Server/static/Server.js b/Web/Server/static/Server.js
index 49f1f13..30274f2 100644
--- a/Web/Server/static/Server.js
+++ b/Web/Server/static/Server.js
@@ -2,4 +2,9 @@ function showLoad(){
var paragraph = document.getElementById("message");
var text = document.createTextNode("RUNNING TEST");
paragraph.appendChild(text);
+
+ var div = document.getElementById("upload");
+ if (div.style.display !== 'none') {
+ div.style.display = 'none';
+ }
}
\ No newline at end of file
diff --git a/Web/Server/templates/index.html b/Web/Server/templates/index.html
new file mode 100644
index 0000000..70a282b
--- /dev/null
+++ b/Web/Server/templates/index.html
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+ ANDI'S PIE
+
+
Select a file to upload
+
+ {% with messages = get_flashed_messages() %}
+ {% if messages %}
+
+ {% for message in messages %}
+ - {{ message }}
+ {% endfor %}
+
+ {% endif %}
+ {% endwith %}
+
+
+
+
+
+
+
+ {% if results %}
+
+ {% endif %}
+
+
+
\ No newline at end of file
diff --git a/Web/Server/templates/upload.html b/Web/Server/templates/upload.html
deleted file mode 100644
index 38c4a09..0000000
--- a/Web/Server/templates/upload.html
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
-
-
-
- Python Flask File Upload Example
- Select a file to upload
-
- {% with messages = get_flashed_messages() %}
- {% if messages %}
-
- {% for message in messages %}
- - {{ message }}
- {% endfor %}
-
- {% endif %}
- {% endwith %}
-
-
-
- {% if results %}
-
- {% endif %}
-
-
\ No newline at end of file
--
cgit v1.2.3