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