uploaded by works, and now you can view art on its own page.
authorNick Retallack <nickretallack@gmil.com>
Sun, 4 Oct 2009 11:42:37 +0000 (04:42 -0700)
committerNick Retallack <nickretallack@gmil.com>
Sun, 4 Oct 2009 11:42:37 +0000 (04:42 -0700)
floof/controllers/art.py
floof/lib/file_storage.py
floof/model/art.py
floof/model/users.py
floof/templates/art/show.mako [new file with mode: 0644]
floof/templates/base.mako
floof/templates/index.mako
floof/websetup.py

index e34543b..6ce9762 100644 (file)
@@ -23,6 +23,10 @@ class ArtController(BaseController):
         
     def upload(self):
         print "PARAMS", request.params
-        Art(**request.params)
+        Art(uploaded_by=c.user, **request.params)
         elixir.session.commit()
         redirect_to(controller="main", action="index")
+
+    def show(self, id):
+        c.art = Art.get(id)
+        return render("/art/show.mako")
\ No newline at end of file
index 1d1c720..0b72690 100644 (file)
@@ -19,7 +19,7 @@ guess_type(temp.filename)[0]
 """
 
 def get_path(space, hash):
-    return os.path.join( space, hash[:2], hash[2:] )
+    return "/" + os.path.join( space, hash[:2], hash[2:] )
     
 
 def save_file(space, temp):   
index e78de41..1df10cc 100644 (file)
@@ -4,7 +4,7 @@
 #   Copyright (c) 2009 Scribblr
 #
 
-from elixir import Entity, Field, Integer, Unicode
+from elixir import Entity, Field, Integer, Unicode
 from elixir import *
 
 from pylons import config
@@ -15,13 +15,12 @@ class Art(Entity):
     title = Field(Unicode(120))
     original_filename = Field(Unicode(120))
     hash = Field(String)
+    uploaded_by = ManyToOne('User')
 
     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():
index 0f05a52..6b06048 100644 (file)
@@ -4,10 +4,12 @@
 #   Copyright (c) 2009 Scribblr
 #
 
-from elixir import Entity, Field, Unicode, belongs_to, has_many
+# from elixir import Entity, Field, Unicode, belongs_to, has_many
+from elixir import *
 
 class User(Entity):
     name = Field(Unicode(20))
+    uploads = OneToMany('Art')
     has_many('identity_urls', of_kind='IdentityURL')
 
 class IdentityURL(Entity):
diff --git a/floof/templates/art/show.mako b/floof/templates/art/show.mako
new file mode 100644 (file)
index 0000000..7d54f98
--- /dev/null
@@ -0,0 +1,5 @@
+<%inherit file="/base.mako" />
+
+<h1>View Art</h1>
+
+<img src="${c.art.get_path()}"
\ No newline at end of file
index 28003c5..5034bf0 100644 (file)
@@ -8,6 +8,8 @@
 </head>
 <body>
 <div id="header">
+<a href="${h.url_for("/")}">Home</a>
+
     <div id="user">
         % if c.user:
         <p>Logged in as ${c.user.name}</p>
@@ -20,6 +22,8 @@
         </form>
         % endif
     </div>
+
+
 </div>
 <div id="body">
 ${next.body()}
index 057399b..e9abdfa 100644 (file)
@@ -1,7 +1,11 @@
 <%inherit file="base.mako" />
 
+<a href="${h.url_for(controller="art", action="new")}">Add New Art!</a>
+
 <ul class="artwork-grid">
     % for artwork in c.artwork:
-    <li><img width="180" src="${artwork.get_path()}"</li>
+    <li><a href="${h.url_for(controller="art", action="show", id=artwork.id)}">
+        <img width="180" src="${artwork.get_path()}">
+    </a></li>
     % endfor
 </ul>
index 7caeed0..b1611c9 100644 (file)
@@ -18,6 +18,7 @@ def setup_app(command, conf, vars):
     # Initialisation here ... this sort of stuff:
 
     # Users
+    from floof.model.users import IdentityURL, User
     identity_url = IdentityURL(url=u'http://eevee.livejournal.com/')
     user = User(name=u'Eevee')
     user.identity_urls.append(identity_url)