*.egg/
*.egg-info/
data/
-public/art/*
+/floof/public/art/*
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
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):
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")
chunk_size = 1024*1024 # TODO: is this a good chunk size?
+from pylons import config
+
"""
Notes:
# Here's one way to move stuff...
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
#
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)
<ul class="artwork-grid">
% for artwork in c.artwork:
- <li>${artwork.title}</li>
+ <li><img width="180" src="${artwork.get_path()}"</li>
% endfor
</ul>