Searching for one tag works. Two tags acts like or and returns multiple copies.
authorNick Retallack <nickretallack@gmil.com>
Sun, 4 Oct 2009 18:12:23 +0000 (11:12 -0700)
committerEevee <git@veekun.com>
Mon, 5 Oct 2009 02:21:00 +0000 (19:21 -0700)
floof/controllers/search.py [new file with mode: 0644]
floof/model/art.py
floof/templates/base.mako
floof/tests/functional/test_search.py [new file with mode: 0644]

diff --git a/floof/controllers/search.py b/floof/controllers/search.py
new file mode 100644 (file)
index 0000000..75926e7
--- /dev/null
@@ -0,0 +1,35 @@
+import logging
+
+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.model.art import Art, Tag, TagText
+import elixir
+
+class SearchController(BaseController):
+
+    def index(self):
+        # Return a rendered template
+        #return render('/search.mako')
+        # or, return a response
+        return 'Hello World'
+
+    def results(self):
+        """ Search, implemented the stupid way! """
+        query = request.params.get('query','')
+        tags = query.split()
+
+        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')
\ No newline at end of file
index fd80d93..420dff8 100644 (file)
@@ -10,11 +10,9 @@ from elixir import *
 from pylons import config
 
 from floof.lib.file_storage import get_path, save_file
-
 from floof.lib.dbhelpers import find_or_create
 
 
-
 class Art(Entity):
     title = Field(Unicode(120))
     original_filename = Field(Unicode(120))
@@ -59,7 +57,7 @@ class Art(Entity):
 
 
 class Tag(Entity):
-    # look into how ondelete works.  It just sets a database property.
+    # look into how ondelete works.  This just sets a database property.
     art = ManyToOne('Art', ondelete='cascade')
     tagger = ManyToOne('User')
     tagtext = ManyToOne('TagText')
index 5034bf0..19f8455 100644 (file)
 <div id="header">
 <a href="${h.url_for("/")}">Home</a>
 
+${h.form (h.url_for(controller="search", action="results"))}
+${h.text('query')} ${h.submit('search','Search')}
+${h.end_form()}
+
     <div id="user">
         % if c.user:
         <p>Logged in as ${c.user.name}</p>
diff --git a/floof/tests/functional/test_search.py b/floof/tests/functional/test_search.py
new file mode 100644 (file)
index 0000000..62c8cd1
--- /dev/null
@@ -0,0 +1,7 @@
+from floof.tests import *
+
+class TestSearchController(TestController):
+
+    def test_index(self):
+        response = self.app.get(url(controller='search', action='index'))
+        # Test response...