diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2013-04-24 18:12:56 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2013-04-24 18:12:56 (GMT) |
commit | 1cdce0801565b5d3d74a5434df993153946e5d57 (patch) | |
tree | 1f3ceece89a0271e435322fde348d657082bc224 | |
parent | 5765ff4f3d242088249b0876683f7d1f217303fd (diff) |
Add a timeout after upload a file
When a file is uploaded, the client need reload the index page,
but need wait until the server prepared the files.
Now reply with a page to reload the index page after a 3 secs timeout.
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r-- | server.py | 26 | ||||
-rw-r--r-- | web/reload_index.html | 12 |
2 files changed, 25 insertions, 13 deletions
@@ -72,9 +72,10 @@ class JournalHTTPRequestHandler(SimpleHTTPRequestHandler): preview_data) #redirect to index.html page - self.send_response(301) - self.send_header('Location', '/web/index.html') - self.end_headers() + self.send_header_response("text/html") + + self.send_file(os.path.join(self.activity_path, + 'web/reload_index.html')) def do_GET(self): """Respond to a GET request.""" @@ -89,11 +90,7 @@ class JournalHTTPRequestHandler(SimpleHTTPRequestHandler): file_path = self.activity_path + self.path if os.path.isfile(file_path): - logging.error('Opening requested file %s', file_path) - f = open(file_path) - content = f.read() - f.close() - self.wfile.write(content) + self.send_file(file_path) if self.path.startswith('/datastore'): # return files requested in the activity instance directory @@ -106,11 +103,14 @@ class JournalHTTPRequestHandler(SimpleHTTPRequestHandler): self.send_header_response(mime_type) if os.path.isfile(file_path): - logging.error('Opening requested file %s', file_path) - f = open(file_path) - content = f.read() - f.close() - self.wfile.write(content) + self.send_file(file_path) + + def send_file(self, file_path): + logging.error('Opening requested file %s', file_path) + f = open(file_path) + content = f.read() + f.close() + self.wfile.write(content) def send_header_response(self, mime_type, file_name=None): self.send_response(200) diff --git a/web/reload_index.html b/web/reload_index.html new file mode 100644 index 0000000..a9d965a --- /dev/null +++ b/web/reload_index.html @@ -0,0 +1,12 @@ +<html> +<head> +<script type="text/javascript"> + function reload_index() { + location.href = "/web/index.html"; + } +</script> +</head> +<body onload="javascript:window.setTimeout(reload_index,3000);"> +Loading... +</body> +</html> |