trying out resource routing. Works decently. Added lots of notes.
[zzz-floof.git] / floof / controllers / search.py
1 import logging
2
3 from pylons import request, response, session, tmpl_context as c, h
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 from floof.model.search import SavedSearch
12 import elixir
13
14 class SearchController(BaseController):
15
16 def index(self):
17 if request.params.get('button') == 'Save':
18 return self.save()
19
20 c.query = request.params.get('query', '')
21 tags = c.query.split()
22
23 tagtexts = TagText.query.filter(TagText.text.in_(tags))
24 tagtext_ids = [_.id for _ in tagtexts]
25
26 # Fetch art that has all the tags
27 c.artwork = Art.query.join(Tag) \
28 .filter(Tag.tagtext_id.in_(tagtext_ids)) \
29 .all()
30
31 return render('/index.mako')
32
33 # TODO: login required
34 def save(self):
35 c.query = request.params.get('query', '')
36 saved_search = SavedSearch(author=c.user, string=c.query)
37 elixir.session.commit()
38 redirect_to(action="list")
39 # TODO: do something better than this.
40
41
42 # TODO: login required
43 def list(self):
44 c.searches = c.user.searches
45 return render('/searches.mako')
46
47 # TODO: login required
48 def display(self, id):
49 c.search = h.get_object_or_404(SavedSearch, id=id)
50 # TODO: create a gallery widget
51
52 redirect_to(controller="users", action="view", name=c.user.name)
53
54
55