75bbba852079a3f462decf3ee857aa9a0c08339f
[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 = [_.id for _ in tagtexts]
28
29 # Fetch art that has all the tags
30 c.artwork = Art.query.join(Tag) \
31 .filter(Tag.id.in_(tagtext_ids)) \
32 .all()
33
34 return render('/index.mako')