Make search a GET to /search.
[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 """Search, implemented the stupid way!"""
17 query = request.params.get('query', '')
18 tags = query.split()
19
20 tagtexts = TagText.query.filter(TagText.text.in_(tags))
21 tagtext_ids = [_.id for _ in tagtexts]
22
23 # Fetch art that has all the tags
24 c.artwork = Art.query.join(Tag) \
25 .filter(Tag.id.in_(tagtext_ids)) \
26 .all()
27
28 return render('/index.mako')