Workout With Friends Stay fit with a little motivation

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Properties
search.py
Go to the documentation of this file.
1 from pyramid.view import view_config, view_defaults
2 from wowf.forms import SearchUserForm, State
3 from wowf.models import User
4 from wowf.views import BaseView
5
6
7 search_view_forms = {'search.users': SearchUserForm}
8
9
10 @view_defaults(route_name='search.users', permission='member')
11 class SearchView(BaseView):
12
13 @view_config(renderer='search/users.html', permission='member')
14 def main(self):
15 form = search_view_forms[self.request.matched_route.name](self.request.GET, state=State(id=self.request.user.id))
16 stream = None
17 if 'q' in self.request.GET and form.validate():
18 stream = form.search(self.settings.max_stream_items)
19 return dict(form=form,
20 stream=stream)
21
22 @view_config(renderer='json', xhr=True)
23 def ajax(self):
24 username = self.request.GET.get('username', '')
25 users = set(User.search(username)) - set([self.request.user])
26 if users:
27 return [{'username': user.username, 'gender': user.gender, 'age': user.age,
28 'avatar': self.request.static_url(user.avatar.small)}
29 for user in users]
30