Merge branch 'bug/13869_disk_defaults' into release/0.10.1
[ganeti_webmgr.git] / ganeti_web / forms / autocomplete_search_form.py
blob6df209eeceb684d6957181ab2c4fb82aa6b6a7b5
1 # Custom Haystack search form for autocomplete searches
3 from haystack.forms import SearchForm
6 class autocomplete_search_form(SearchForm):
7 '''
8 Custom Haystack search form for autocomplete searches. Important so that
9 users can search for 'foo' and get 'foo.bar', 'foo.bar.herp', etc.
10 '''
11 def search(self):
12 '''
13 Overwriting SearchForm's default search to implement autocomplete
14 searching.
15 '''
16 if not self.is_valid():
17 return self.no_query_found()
19 if not self.cleaned_data.get('q'):
20 return self.no_query_found()
22 # Perform an autocomplete search query on the 'content_auto' fields of
23 # the searchable models
24 sqs = self.searchqueryset.autocomplete(
25 content_auto=self.cleaned_data['q'])
27 if self.load_all:
28 sqs = sqs.load_all()
30 return sqs