displaying galleries on your page works
authorNick Retallack <nickretallack@gmil.com>
Wed, 7 Oct 2009 03:27:45 +0000 (20:27 -0700)
committerNick Retallack <nickretallack@gmil.com>
Wed, 7 Oct 2009 03:27:45 +0000 (20:27 -0700)
13 files changed:
floof/config/routing.py
floof/controllers/gallery.py [new file with mode: 0644]
floof/controllers/search.py
floof/controllers/tag.py
floof/lib/search.py
floof/model/search.py
floof/model/users.py
floof/public/layout.css
floof/templates/base.mako
floof/templates/index.mako
floof/templates/macros.mako [new file with mode: 0644]
floof/templates/users/view.mako
floof/tests/functional/test_gallery.py [new file with mode: 0644]

index 9c3da14..7f46a2c 100644 (file)
@@ -42,7 +42,7 @@ def make_map():
     map.connect('/account/register_finish', controller='account', action='register_finish', **require_POST)
 
     map.connect('/users', controller='users', action='list')
-    map.connect('/users/{name}', controller='users', action='view')
+    map.connect('user_page', '/users/{name}', controller='users', action='view')
 
     # Art stuff
     art = map.resource('art','art', controller="art", member={'rate':'PUT'})
@@ -77,7 +77,8 @@ def make_map():
     # map.connect('/tag/{id}/delete', controller='tag', action='delete')
 
     map.connect('search', '/search', controller='search', action='index')
-    map.connect('/search/list', controller='search', action='list')
+    # map.connect( '/search/{query}', controller='search', action='index')
+    map.connect('saved_searches', '/search/list', controller='search', action='list')
 
 
     # default routing is back so we can test stuff.
diff --git a/floof/controllers/gallery.py b/floof/controllers/gallery.py
new file mode 100644 (file)
index 0000000..e923e30
--- /dev/null
@@ -0,0 +1,17 @@
+import logging
+
+from pylons import request, response, session, tmpl_context as c, h
+from pylons.controllers.util import abort, redirect
+from pylons import url
+
+from floof.lib.base import BaseController, render
+
+log = logging.getLogger(__name__)
+import elixir
+from floof.model.search import GalleryWidget
+class GalleryController(BaseController):
+
+    def delete(self, id):
+        c.gallery = h.get_object_or_404(GalleryWidget, id=id)
+        elixir.session.delete(tag)
+        elixir.session.commit()
index 3b6faef..e27e5c8 100644 (file)
@@ -1,14 +1,16 @@
 import logging
 
 from pylons import request, response, session, tmpl_context as c, h
-from pylons.controllers.util import abort, redirect_to
+from pylons.controllers.util import abort, redirect
+from pylons import url
 
 from floof.lib.base import BaseController, render
+from floof.lib.search import do_search
 
 log = logging.getLogger(__name__)
 
 from floof.model.art import Art, Tag, TagText
-from floof.model.search import SavedSearch
+from floof.model.search import SavedSearch, GalleryWidget
 import elixir
 
 class SearchController(BaseController):
@@ -18,16 +20,7 @@ class SearchController(BaseController):
             return self.save()
         
         c.query = request.params.get('query', '')
-        tags = c.query.split()
-        
-        tagtexts = TagText.query.filter(TagText.text.in_(tags))
-        tagtext_ids = [_.id for _ in tagtexts]
-
-        # Fetch art that has all the tags
-        c.artwork = Art.query.join(Tag) \
-                       .filter(Tag.tagtext_id.in_(tagtext_ids)) \
-                       .all()
-
+        c.artwork = do_search(c.query)
         return render('/index.mako')
         
     # TODO: login required
@@ -35,7 +28,7 @@ class SearchController(BaseController):
         c.query = request.params.get('query', '')
         saved_search = SavedSearch(author=c.user, string=c.query)
         elixir.session.commit()
-        redirect_to(action="list")
+        redirect(url('saved_searches'))
         # TODO: do something better than this.
         
     
@@ -47,9 +40,9 @@ class SearchController(BaseController):
     # TODO: login required
     def display(self, id):
         c.search = h.get_object_or_404(SavedSearch, id=id)
-        # TODO: create a gallery widget
-        
-        redirect_to(controller="users", action="view", name=c.user.name)
+        c.gallery = GalleryWidget(search=c.search, displayer=c.user)
+        elixir.session.commit()
+        redirect(url(controller="users", action="view", name=c.user.name))
         
         
         
\ No newline at end of file
index d8e46f3..ef3c7ce 100644 (file)
@@ -15,10 +15,9 @@ class TagController(BaseController):
 
     # TODO: login required
     def delete(self, art_id, id):
-        tag = Tag.get(id)
-        if tag:
-            elixir.session.delete(tag)
-            elixir.session.commit()
+        tag = h.get_object_or_404(Tag, id=id)
+        elixir.session.delete(tag)
+        elixir.session.commit()
         redirect(url('art', id=art_id))
         
     # TODO: login required
index 3acb248..f7ce65b 100644 (file)
@@ -1,3 +1,23 @@
+from floof.model.art import Art, Tag, TagText
+
+def do_search(query):
+    tags = query.split()
+
+    tagtexts = TagText.query.filter(TagText.text.in_(tags))
+    tagtext_ids = [_.id for _ in tagtexts]
+
+    # Fetch art that has all the tags
+    artwork = Art.query.join(Tag) \
+                   .filter(Tag.tagtext_id.in_(tagtext_ids)) \
+                   .all()
+    return artwork
+
+
+
+
+
+
+# unfinished stuff
 def parse(query):
     words = query.split()
 
@@ -18,16 +38,6 @@ def parse(query):
                 # TODO: Find stuff that has this rating
                 # Rating.query.filter(Rating.s)
 
-
-
-
     tagtexts = TagText.query.filter(TagText.text.in_(tags))
     tagtext_ids = map(lambda x:x.id, tagtexts)
 
-    # TODO: this is wrong.  Please fix it so it returns art that has all the tags.
-    art_tag_pairs = elixir.session.query(Art,Tag).filter(Art.id == Tag.art_id).\
-        filter(Tag.tagtext_id.in_(tagtext_ids)).all()
-
-    # just the art please.
-    c.artwork = map(lambda x: x[0], art_tag_pairs)
-    return render('/index.mako')
index 011468c..e812afc 100644 (file)
@@ -1,30 +1,42 @@
 from elixir import *
-from users import User
+# from users import User
+
+from floof.lib.search import do_search
 
 class SavedSearch(Entity):
     string = Field(Unicode) # I tried calling this query, but it broke elixir
-    author = ManyToOne(User)
+    author = ManyToOne('User')
     
     def __unicode__(self):
         return self.string
+        
+    @property
+    def results(self):
+        return do_search(self.string)
+
 
 
 class GalleryWidget(Entity):
     search = ManyToOne(SavedSearch)
-    displayer = ManyToOne(User) # determines whose page should it should show up on
+    displayer = ManyToOne('User') # determines whose page should it should show up on
                                 # Could be no-ones, if it's just a template.
     
     # Needs some fields for position on your page
 
     @property
-    def query(self):
-        return self.search.query
+    def string(self):
+        return self.search
     
-    @query.setter
-    def query(self, value):
+    @string.setter
+    def string(self, value):
         # TODO: should we delete the possibly orphaned saved search?
         if not self.displayer:
             # TODO: may have to refactor this into an init if the key ordering is inconvenienc
             raise "Oh no!  This gallery needs a displayer to set on the saved search."
         
-        self.search = SavedSearch(author=self.displayer, query=value)
\ No newline at end of file
+        self.search = SavedSearch(author=self.displayer, string=value)
+        
+        
+# class UserPage(Entity):
+#     owner = ManyToOne('User')
+#     visible = Field(Boolean)
\ No newline at end of file
index 5c9783e..d4a679a 100644 (file)
@@ -12,6 +12,7 @@ class User(Entity):
     uploads = OneToMany('Art')
     has_many('identity_urls', of_kind='IdentityURL')
     searches = OneToMany('SavedSearch')
+    galleries = OneToMany('GalleryWidget')
     
     def __unicode__(self):
         return self.name
index 25737d0..a098b5e 100644 (file)
@@ -10,6 +10,9 @@ body { font-family: sans-serif; font-size: 12px; }
 
 .full {display:block;}
 
+
+.artwork-grid li {display:inline;}
+
 /*** Common bits and pieces ***/
 /* General form layout */
 a {color:blue; text-decoration:none; pointer:cursor;} /* Who needs visited links */
index 13126f7..7290a11 100644 (file)
@@ -32,7 +32,7 @@ ${h.end_form()}
     <div id="user">
         % if c.user:
         <form action="${url(controller='account', action='logout')}" method="POST">
-        <p>Logged in as ${c.user.name}.  ${h.submit(None, 'Log out')}</p>
+        <p>Logged in as <a href="${h.url('user_page', name=c.user.name)}">${c.user.name}</a>.  ${h.submit(None, 'Log out')}</p>
         </form>
         % else:
         <form action="${url(controller='account', action='login_begin')}" method="POST">
index 8ee86e6..a774551 100644 (file)
@@ -1,10 +1,4 @@
 <%inherit file="base.mako" />
+<%namespace name="macros" file="/macros.mako" />
 
-
-<ul class="artwork-grid">
-    % for artwork in c.artwork:
-    <li><a href="${h.url("art", id=artwork.id)}">
-        <img width="180" src="${artwork.get_path()}">
-    </a></li>
-    % endfor
-</ul>
+${macros.thumbs(c.artwork)}
diff --git a/floof/templates/macros.mako b/floof/templates/macros.mako
new file mode 100644 (file)
index 0000000..5633e5b
--- /dev/null
@@ -0,0 +1,11 @@
+<%def name="thumbs(art)">
+    <ul class="artwork-grid">
+        % for item in art:
+            <li>
+                <a href="${h.url("art", id=item.id)}">
+                    <img width="180" src="${item.get_path()}">
+                </a>
+            </li>
+        % endfor
+    </ul>
+</%def>
\ No newline at end of file
index 9f39bae..d128276 100644 (file)
@@ -1,3 +1,9 @@
 <%inherit file="/base.mako" />
+<%namespace name="macros" file="/macros.mako" />
 
 <p>This is the userpage for ${c.this_user.name}.</p>
+
+% for gallery in c.this_user.galleries:
+<h2>${gallery.string}</h2>
+${macros.thumbs(gallery.search.results)}
+% endfor
\ No newline at end of file
diff --git a/floof/tests/functional/test_gallery.py b/floof/tests/functional/test_gallery.py
new file mode 100644 (file)
index 0000000..695513c
--- /dev/null
@@ -0,0 +1,7 @@
+from floof.tests import *
+
+class TestGalleryController(TestController):
+
+    def test_index(self):
+        response = self.app.get(url(controller='gallery', action='index'))
+        # Test response...