now you can post art. No associated user yet though.
authorNick Retallack <nickretallack@gmil.com>
Sun, 4 Oct 2009 11:16:14 +0000 (04:16 -0700)
committerNick Retallack <nickretallack@gmil.com>
Sun, 4 Oct 2009 11:16:14 +0000 (04:16 -0700)
.gitignore
development.ini
floof/controllers/art.py
floof/lib/file_storage.py
floof/model/art.py
floof/templates/index.mako

index bc97b44..abc747b 100644 (file)
@@ -5,4 +5,4 @@
 *.egg/
 *.egg-info/
 data/
-public/art/*
+/floof/public/art/*
index 0c39bba..f184f66 100644 (file)
@@ -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
index dd06f12..e34543b 100644 (file)
@@ -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")
index 5595e88..1d1c720 100644 (file)
@@ -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 
index 725b9e8..e78de41 100644 (file)
@@ -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)
index ce3a112..057399b 100644 (file)
@@ -2,6 +2,6 @@
 
 <ul class="artwork-grid">
     % for artwork in c.artwork:
-    <li>${artwork.title}</li>
+    <li><img width="180" src="${artwork.get_path()}"</li>
     % endfor
 </ul>