Mercurial > public > sg101
diff custom_search/views.py @ 763:20a3bf7a6370
Add username to search query logging.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 19 Jan 2014 11:25:45 -0600 |
parents | |
children | 840c1a8bd8af |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/custom_search/views.py Sun Jan 19 11:25:45 2014 -0600 @@ -0,0 +1,17 @@ +"""Custom views for searching.""" + +from haystack.views import SearchView + + +class UserSearchView(SearchView): + """This class passes the user making the search as an __init__ argument to + the search form as the keyword argument 'user'. + + """ + def build_form(self, form_kwargs=None): + """Pass the request.user object to the form's constructor.""" + if not form_kwargs: + form_kwargs = {} + if 'user' not in form_kwargs: + form_kwargs['user'] = self.request.user + return super(UserSearchView, self).build_form(form_kwargs)