Skip to content

Commit

Permalink
File description field
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarrientos committed Sep 30, 2010
1 parent fcb7cad commit aabd2b3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app.py
Expand Up @@ -13,7 +13,8 @@
from handlers import MainHandler, UploadHandler

define("port", default=8888, help="run on the given port", type=int)
define("storage", default="/tmp/storage", help="dir", type=str)
define("storage", default="/tmp/storage", help="FIXME", type=str)
define("desc_min_len", default=15, help="FIXME", type=int)


class Application(tornado.web.Application):
Expand Down
6 changes: 6 additions & 0 deletions handlers.py
Expand Up @@ -37,10 +37,16 @@ def _count_hosted_files(self):
return row

class UploadHandler(BaseHandler):
_ERRORS = { 'EDESCTOOSHORT' : "Description is too small." }

def get(self):
raise tornado.web.HTTPError(403)

def post(self):
desc = tornado.escape.xhtml_escape(self.get_argument("description"))
if len(desc) < options.desc_min_len:
self.render("uploadfailure.html", reason=self._ERRORS['EDESCTOOSHORT'])

for f in self.request.files['payload']:
local_fileid = self._get_sha1_sum(f['body'])
db_fileid, filesize = self._check_file_existence(local_fileid)
Expand Down
4 changes: 4 additions & 0 deletions templates/uploadform.html
Expand Up @@ -4,7 +4,11 @@
<h2>Hosted files: {{ hosted_files }}</h2>
{% end %}
<form method="post" action="/upload" enctype="multipart/form-data">
<label for="description">Write a short description</label>
<input id="description" type="text" name="description"/>
<br/>
<label for="file">Choose a file to upload...</label><input id="file" type="file" name="payload"/>
<br/>
<input type="submit" value="Upload!"/>
</form>
</body>
Expand Down

0 comments on commit aabd2b3

Please sign in to comment.