src/p4l/search/forms.py
changeset 113 c05567404888
child 115 4749704f9b40
equal deleted inserted replaced
112:ba6056f58516 113:c05567404888
       
     1 # -*- coding: utf-8 -*-
       
     2 '''
       
     3 Created on Sep 20, 2013
       
     4 
       
     5 @author: ymh
       
     6 '''
       
     7 from haystack.forms import SearchForm
       
     8 
       
     9 from p4l.utils import strip_accents
       
    10 
       
    11 
       
    12 class RecordSearchForm(SearchForm):
       
    13     
       
    14     def __init__(self, *args, **kwargs):
       
    15         SearchForm.__init__(self, *args, **kwargs)
       
    16         
       
    17     def no_query_found(self):
       
    18         return self.searchqueryset.all()
       
    19     
       
    20     def search(self):
       
    21         if not self.is_valid():
       
    22             return self.no_query_found()
       
    23 
       
    24         if not self.cleaned_data.get('q'):
       
    25             return self.no_query_found()
       
    26 
       
    27         sqs = self.searchqueryset.auto_query(strip_accents(self.cleaned_data['q']))
       
    28 
       
    29         if self.load_all:
       
    30             sqs = sqs.load_all()
       
    31 
       
    32         return sqs