Permalink
Browse files

initial version of AppEngine app for distributing bookware

  • Loading branch information...
1 parent d8cd379 commit 8272fc067ab49df539544ba6c0717a5bc6ae73c4 @armandofox armandofox committed Dec 31, 2011
Showing with 111 additions and 0 deletions.
  1. +8 −0 app.yaml
  2. +58 −0 bookware.py
  3. +26 −0 index.html
  4. +9 −0 main.css
  5. +10 −0 template.html
View
@@ -0,0 +1,8 @@
+application: bookware
+version: 1
+runtime: python
+api_version: 1
+
+handlers:
+- url: /.*
+ script: bookware.py
View
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+#
+
+import os
+import urllib
+
+from google.appengine.ext import blobstore
+from google.appengine.ext import webapp
+from google.appengine.ext.webapp import blobstore_handlers
+from google.appengine.ext.webapp import template
+from google.appengine.ext.webapp.util import run_wsgi_app
+
+class AddFileHandler(webapp.RequestHandler):
+ def get(self):
+ upload_url = blobstore.create_upload_url('/admin/upload')
+ body = """
+ <form action="%s" method="POST" enctype="multipart/form-data">
+ Upload File:
+ <input type="file" name="file"><br/>
+ <input type="submit" name="submit" value="Upload">
+ </form>
+ """ % upload_url
+ self.response.out.write(template.render('template.html', {'body': body}))
+
+class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
+ def post(self):
+ upload_files = self.get_uploads('file') # 'file' is file upload field in the form
+ blob_info = upload_files[0]
+ body = """
+ <h3>Uploaded file '%s' (%d bytes) as /files/%s</h3>
+ <p>
+ <a href="/admin/add">Add another</a> | <a href="/">List</a>
+ </p>
+ """ % (blob_info.filename, blob_info.size, blob_info.key())
+ self.response.out.write(template.render('template.html', {'body': body}))
+
+class ListHandler(webapp.RequestHandler):
+ def get(self):
+ self.response.out.write(template.render('index.html', {'blobs': blobstore.BlobInfo.all() }))
+
+class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
+ def get(self, resource):
+ resource = str(urllib.unquote(resource))
+ blob_info = blobstore.BlobInfo.get(resource)
+ self.send_blob(blob_info)
+
+def main():
+ application = webapp.WSGIApplication(
+ [('/admin/add', AddFileHandler),
+ ('/admin/upload', UploadHandler),
+ ('/files/?$', ListHandler),
+ ('/?$', ListHandler),
+ ('/files/([^/]+)?', ServeHandler),
+ ], debug=True)
+ run_wsgi_app(application)
+
+if __name__ == '__main__':
+ main()
View
@@ -0,0 +1,26 @@
+<html>
+ <head>
+ <link type="text/css" rel="stylesheet" href="/main.css"/>
+ </head>
+ <body>
+
+ <h1>Downloadable Files</h1>
+
+ <table>
+ <thead>
+ <th>File</th>
+ <th>Size (bytes)</th>
+ <th>Upload date (UTC)</th>
+ </thead>
+ <tbody>
+ {% for blob in blobs %}
+ <tr>
+ <td><a href="/files/{{ blob.key }}">{{ blob.filename }}</a></td>
+ <td>{{ blob.size }}</td>
+ <td>{{ blob.creation.ctime }}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </body>
+</html>
View
@@ -0,0 +1,9 @@
+th, td {
+ text-align: left;
+ margin: 0 2ex;
+ color: red;
+}
+
+h1 {
+ border-bottom: 1px solid black;
+}
View
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <link type="text/css" rel="stylesheet" href="/main.css"/>
+ </head>
+ <body>
+
+ {{ body }}
+
+ </body>
+</html>

0 comments on commit 8272fc0

Please sign in to comment.