86179666e5310cd1706414c334293c4d65be8748
[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
5 from pylons import url
6
7 from floof.lib import helpers as h
8 from floof.lib.base import BaseController, render
9 from floof.lib.tags import parse
10
11 log = logging.getLogger(__name__)
12
13 from floof.model import Art, Tag, TagText
14 from floof.model import SavedSearch, GalleryWidget
15 import elixir
16
17 class SearchController(BaseController):
18
19 def index(self):
20 if request.params.get('button') == 'Save':
21 return self.save()
22
23 c.query = request.params.get('query', '')
24 c.artwork = parse(c.query).all()
25 return render('/index.mako')
26
27 # TODO: login required
28 def save(self):
29 c.query = request.params.get('query', '')
30 saved_search = SavedSearch(author=c.user, string=c.query)
31 elixir.session.commit()
32 redirect(url('saved_searches'))
33 # TODO: do something better than this.
34
35
36 # TODO: login required
37 def list(self):
38 c.searches = c.user.searches
39 return render('/searches.mako')
40
41 # TODO: login required
42 def display(self, id):
43 c.search = h.get_object_or_404(SavedSearch, id=id)
44 c.gallery = GalleryWidget(search=c.search, page=c.user.primary_page)
45 elixir.session.commit()
46 redirect(url(controller="users", action="view", name=c.user.name))
47
48