From: Nick Retallack Date: Sun, 4 Oct 2009 11:16:14 +0000 (-0700) Subject: now you can post art. No associated user yet though. X-Git-Url: http://git.veekun.com/zzz-floof.git/commitdiff_plain/f7617496a08f10a77eb909982dae4e995c132900?ds=inline now you can post art. No associated user yet though. --- diff --git a/.gitignore b/.gitignore index bc97b44..abc747b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ *.egg/ *.egg-info/ data/ -public/art/* +/floof/public/art/* diff --git a/development.ini b/development.ini index 0c39bba..f184f66 100644 --- a/development.ini +++ b/development.ini @@ -19,7 +19,7 @@ port = 5000 use = egg:floof full_stack = true static_files = true -art_root = %(here)s/public/art +static_root = %(here)s/floof/public/ cache_dir = %(here)s/data beaker.session.key = floof diff --git a/floof/controllers/art.py b/floof/controllers/art.py index dd06f12..e34543b 100644 --- a/floof/controllers/art.py +++ b/floof/controllers/art.py @@ -1,15 +1,14 @@ import logging -from pylons import request, response, session, tmpl_context as c, config +from pylons import request, response, session, tmpl_context as c from pylons.controllers.util import abort, redirect_to from floof.lib.base import BaseController, render log = logging.getLogger(__name__) - - -from floof.lib.file_storage import save_file +import elixir +from floof.model.art import Art class ArtController(BaseController): @@ -23,7 +22,7 @@ class ArtController(BaseController): def upload(self): - file = request.POST['file'] - root = config['app_conf']['art_root'] - save_file(root, file) + print "PARAMS", request.params + Art(**request.params) + elixir.session.commit() redirect_to(controller="main", action="index") diff --git a/floof/lib/file_storage.py b/floof/lib/file_storage.py index 5595e88..1d1c720 100644 --- a/floof/lib/file_storage.py +++ b/floof/lib/file_storage.py @@ -3,6 +3,8 @@ import os, shutil, tempfile, hashlib chunk_size = 1024*1024 # TODO: is this a good chunk size? +from pylons import config + """ Notes: # Here's one way to move stuff... @@ -16,8 +18,14 @@ from mimetypes import guess_type guess_type(temp.filename)[0] """ +def get_path(space, hash): + return os.path.join( space, hash[:2], hash[2:] ) + -def save_file(dest_root, temp): +def save_file(space, temp): + + dest_root = os.path.join( config['app_conf']['static_root'], space ) + # we don't know where we're going to save this stuff yet, # so I guess we'll write it to another tempfile. One we know the path of. # I'm assuming the tempfile we get from pylons is set to delete itself diff --git a/floof/model/art.py b/floof/model/art.py index 725b9e8..e78de41 100644 --- a/floof/model/art.py +++ b/floof/model/art.py @@ -5,8 +5,30 @@ # from elixir import Entity, Field, Integer, Unicode +from elixir import * + +from pylons import config + +from floof.lib.file_storage import get_path, save_file class Art(Entity): title = Field(Unicode(120)) - # filename = Field(Unicode(120)) + original_filename = Field(Unicode(120)) + hash = Field(String) + + def __init__(self, **kwargs): + # I wanted to check for the existence of the file, but... + # for some reason this FieldStorage object always conditions as falsey. + self.hash = save_file("art", kwargs.pop('file')) + + + super(Art, self).__init__(**kwargs) + # this is what super is doing, pretty much. + # for key, value in kwargs.items(): + # setattr(self, key, value) + + + def get_path(self): + if self.hash: + return get_path("art", self.hash) diff --git a/floof/templates/index.mako b/floof/templates/index.mako index ce3a112..057399b 100644 --- a/floof/templates/index.mako +++ b/floof/templates/index.mako @@ -2,6 +2,6 @@