aboutsummaryrefslogtreecommitdiffstats
path: root/Web/Server
diff options
context:
space:
mode:
authorDat Nguyen <nguy2854@umn.edu>2019-11-21 13:45:20 -0600
committerDat Nguyen <nguy2854@umn.edu>2019-11-21 13:45:20 -0600
commit20f9ea9141f77b3c21232efc30202408d535de18 (patch)
tree63fd03429f904a6628c7ff586c6e8cbe240132b2 /Web/Server
parentUpdate PI.py (diff)
downloadee4511w-20f9ea9141f77b3c21232efc30202408d535de18.tar
ee4511w-20f9ea9141f77b3c21232efc30202408d535de18.tar.gz
ee4511w-20f9ea9141f77b3c21232efc30202408d535de18.tar.bz2
ee4511w-20f9ea9141f77b3c21232efc30202408d535de18.tar.lz
ee4511w-20f9ea9141f77b3c21232efc30202408d535de18.tar.xz
ee4511w-20f9ea9141f77b3c21232efc30202408d535de18.tar.zst
ee4511w-20f9ea9141f77b3c21232efc30202408d535de18.zip
working web stuff with running page
Diffstat (limited to '')
-rw-r--r--Web/Server/Results/results.txt2
-rw-r--r--Web/Server/Server.py30
-rw-r--r--Web/Server/static/Server.js5
-rw-r--r--Web/Server/templates/index.html43
-rw-r--r--Web/Server/templates/upload.html37
5 files changed, 66 insertions, 51 deletions
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 @@
+<html>
+ <head>
+ <link rel="stylesheet" href="/static/Server.css">
+ <script type="text/javascript" src="/static/Server.js"></script>
+ </head>
+ <body>
+ <title>ANDI'S PIE</title>
+ <div id="upload">
+ <h2>Select a file to upload</h2>
+ <p>
+ {% with messages = get_flashed_messages() %}
+ {% if messages %}
+ <ul class=flashes>
+ {% for message in messages %}
+ <li>{{ message }}</li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+ {% endwith %}
+ </p>
+
+ <form method="post" action="/upload" enctype="multipart/form-data">
+ <dl>
+ <p>
+ <input type="file" name="file" autocomplete="off" required>
+ </p>
+ </dl>
+ <p>
+ <input type="submit" value="Submit" onclick="showLoad()">
+ </p>
+ </form>
+ </div>
+
+ <div id="message"></div>
+
+ {% if results %}
+ <form method="get" action="/results">
+ <button type="submit">Download!</button>
+ </form>
+ {% endif %}
+
+ </body>
+</html> \ 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 @@
-<html>
- <head>
- <link rel="stylesheet" href="/static/Server.css">
- <script type="text/javascript" src="/static/Server.js"></script>
- </head>
- <body>
- <title>Python Flask File Upload Example</title>
- <h2>Select a file to upload</h2>
- <p id = "message">
- {% with messages = get_flashed_messages() %}
- {% if messages %}
- <ul class=flashes>
- {% for message in messages %}
- <li>{{ message }}</li>
- {% endfor %}
- </ul>
- {% endif %}
- {% endwith %}
- </p>
- <form method="post" action="/upload" enctype="multipart/form-data">
- <dl>
- <p>
- <input type="file" name="file" autocomplete="off" required>
- </p>
- </dl>
- <p>
- <input type="submit" value="Submit" onclick="showLoad()">
- </p>
- </form>
-
- {% if results %}
- <form method="get" action="/results">
- <button type="submit">Download!</button>
- </form>
- {% endif %}
- </body>
-</html> \ No newline at end of file