Browse Source

added download handler.

Signed-off-by: Nicholas Tan Jerome <nicholas.jerome@kit.edu>
Nicholas Tan Jerome 6 years ago
parent
commit
4a0b2b9c9c

+ 39 - 4
index.py

@@ -1,4 +1,4 @@
-# coding=utf-8
+#coding=utf-8
 import os
 
 import tornado.httpserver
@@ -14,6 +14,7 @@ class Application(tornado.web.Application):
     def __init__(self):
         handlers = [
             (r"/", MainHandler),
+            (r"/download", GenFileStreamerHandler),
         ]
         settings = dict(
             template_path=os.path.join(os.path.dirname(__file__), "templates"),
@@ -25,6 +26,7 @@ class Application(tornado.web.Application):
 
 class MainHandler(tornado.web.RequestHandler):
     def get(self):
+        
         self.render(
             "index.html",
             title = """Preservation of three-dimensional anatomy in phosphatized 
@@ -35,15 +37,48 @@ class MainHandler(tornado.web.RequestHandler):
                 University of Bonn, Bonn, Germany; ANKA/Institute for Photon Science and 
                 Synchrotron Radiation, Karlsruhe Institute of Technology, Eggenstein-Leopoldshafen, 
                 Germany; Department of Agricultural and Environmental Sciences, Clemson University, 
-                Clemson, United States; State Museum of Natural History Stuttgart, Stuttgart,Germany; 
+                Clemson, United States; State Museum of Natural History Stuttgart, Stuttgart, Germany; 
                 Institute of Crop Science and Resource Conservation, University of Bonn, Bonn, Germany; 
                 Laboratory for Applications of Synchrotron Radiation, Karlsruhe Institute of Technology, 
-                Karlsruhe, Germany"""
+                Karlsruhe, Germany""",
+            data_list = [
+                "NRM-PZ_Ar65716",
+                "Saab",
+                "Mercedes",
+                "Audi"],
+            desc = "<i>Xenomorphia resurrecta</i>, male; well-preserved, head hollow",
+            data_size = "1.3 GB"
         )
 
 
+class GenFileStreamerHandler(tornado.web.RequestHandler):
+    # 0.5 MB
+    CHUNK_SIZE = 512000
+    #def initialize(self, file_path):
+    #    self.path = file_path
+    @tornado.web.asynchronous
+    @tornado.gen.engine
+    def get(self):
+        #print self.get_arguments("did")
+        self.path = '/Users/ntj/Development/fossil/data/01_NRM-PZ_Ar65716/test.zip'
+        file_name = "01_NRM-PZ_Ar65716.zip"
+        #self.set_header("Content-Type", "text/plain")
+        self.set_header('Content-Type', 'application/octet-stream')
+        self.set_header('Content-Disposition', 'attachment; filename=' + file_name)
+        self.set_header("Content-Length", os.path.getsize(self.path))
+        self.flush()
+        fd = open(self.path, "rb")
+        data = fd.read(self.CHUNK_SIZE)
+        while data:
+            self.write(data)
+            yield tornado.gen.Task(self.flush)
+            data = fd.read(self.CHUNK_SIZE)
+        fd.close()
+        self.finish()
+
+
 if __name__ == "__main__":
     tornado.options.parse_command_line()
     http_server = tornado.httpserver.HTTPServer(Application())
     http_server.listen(options.port)
-    tornado.ioloop.IOLoop.instance().start()
+    tornado.ioloop.IOLoop.instance().start()

BIN
static/css/.DS_Store


File diff suppressed because it is too large
+ 3 - 0
static/css/jquery-ui.min.css


+ 0 - 24
static/css/quicksand.css

@@ -1,24 +0,0 @@
-/* vietnamese */
-@font-face {
-  font-family: 'myquick';
-  font-style: normal;
-  font-weight: 400;
-  src: url(/static/font/Quicksand-Bold.ttf) format('ttf');
-  unicode-range: U+0102-0103, U+1EA0-1EF9, U+20AB;
-}
-/* latin-ext */
-@font-face {
-  font-family: 'myquick';
-  font-style: normal;
-  font-weight: 400;
-  src: url(/static/font/Quicksand-Bold.ttf) format('ttf');
-  unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
-}
-/* latin */
-@font-face {
-  font-family: 'myquick';
-  font-style: normal;
-  font-weight: 400;
-  src: url(/static/font/Quicksand-Bold.ttf) format('ttf');
-  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
-}

+ 1 - 1
static/css/style.css

@@ -180,7 +180,7 @@ hr {
     padding: 30px;
 	text-align: center;
     vertical-align: middle;
-	font-weight: bold;
+
 	font-size: 25px;
 }
 

File diff suppressed because it is too large
+ 1 - 0
static/js/jquery-1.12.4.min.js


File diff suppressed because it is too large
+ 5 - 0
static/js/jquery-ui.min.js


+ 12 - 11
templates/index.html

@@ -7,7 +7,7 @@
     <title>The Fossils Data</title>
     <meta name="description" content="Institute for Data Processing and Electronics">
     <meta name="author" content="Nicholas Tan Jerome">
-
+    <link rel="stylesheet" href="{{ static_url("css/jquery-ui.min.css") }}">
     <link rel="stylesheet" href="{{ static_url("css/style.css") }}">
 
     <!--[if lt IE 9]>
@@ -51,13 +51,13 @@
     
     <div id="subheader">
         <span>Sample:</span> 
-        <select>
-            <option value="1">NRM-PZ_Ar65716</option>
-            <option value="2">Saab</option>
-            <option value="3">Mercedes</option>
-            <option value="4">Audi</option>
+        <select style="width: auto;">
+            {% for i, sample_name in enumerate(data_list) %}
+                <option value={{ i+1 }}>{{ i+1 }}_{{ sample_name }}</option>
+            {% end %}
         </select>
-        <img class="icon" onclick="onClick1('left')" src="{{ static_url("img/icon/download.svg") }}"/>
+        <img class="icon" src="{{ static_url("img/icon/download.svg") }}"/>
+        <span>({{ data_size }})</span>
     </div>
 
     <div id="image-container" class="clearfix">
@@ -100,16 +100,17 @@
     
     <div id="text-block">
         <div id="text-desc">
-            <p><span>Description</span><i>Xenomorphia resurrecta</i>, male; well-preserved, head hollow</p>
+            <p><span>Description</span>{{ desc }}</p>
         </div>
         <div id="details">
             <p><span>Overview</span></p>
             <img src="{{ static_url("data/NRM-PZ_Ar65716.jpg") }}"/>
         </div>
     </div>
-<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>
+
+<script src="{{ static_url("js/jquery-1.12.4.min.js") }}"></script>
+<script src="{{ static_url("js/jquery-ui.min.js") }}"></script>
 <script src="{{ static_url("js/script.js") }}"></script>
 </body>
 </html>
+

Some files were not shown because too many files changed in this diff