75926e7d22316ca9465d0c095214d376f8a31fc9
[zzz-floof.git] / floof / controllers / search.py
1 import logging
2
3 from pylons import request, response, session, tmpl_context as c
4 from pylons.controllers.util import abort, redirect_to
5
6 from floof.lib.base import BaseController, render
7
8 log = logging.getLogger(__name__)
9
10 from floof.model.art import Art, Tag, TagText
11 import elixir
12
13 class SearchController(BaseController):
14
15 def index(self):
16 # Return a rendered template
17 #return render('/search.mako')
18 # or, return a response
19 return 'Hello World'
20
21 def results(self):
22 """ Search, implemented the stupid way! """
23 query = request.params.get('query','')
24 tags = query.split()
25
26 tagtexts = TagText.query.filter(TagText.text.in_(tags))
27 tagtext_ids = map(lambda x:x.id, tagtexts)
28
29 # TODO: this is wrong. Please fix it so it returns art that has all the tags.
30 art_tag_pairs = elixir.session.query(Art,Tag).filter(Art.id == Tag.art_id).\
31 filter(Tag.tagtext_id.in_(tagtext_ids)).all()
32
33 # just the art please.
34 c.artwork = map(lambda x: x[0], art_tag_pairs)
35 return render('/index.mako')