diff options
author | Pierre-Yves Chibon <pingou@pingoured.fr> | 2012-03-19 19:34:17 +0100 |
---|---|---|
committer | Pierre-Yves Chibon <pingou@pingoured.fr> | 2012-03-19 19:34:17 +0100 |
commit | cb1ac726282db504a522acf83cbd78da15de0895 (patch) | |
tree | 8443c2ddf0b2c1e47404803bfa50fdf4b8e53c73 /views/pages.py | |
parent | 727b65c8b66ed802ecd315a255fa0172c4a3eeef (diff) | |
download | hyperkitty-cb1ac726282db504a522acf83cbd78da15de0895.tar.gz hyperkitty-cb1ac726282db504a522acf83cbd78da15de0895.tar.xz hyperkitty-cb1ac726282db504a522acf83cbd78da15de0895.zip |
Implement search in the different part of the email
Diffstat (limited to 'views/pages.py')
-rw-r--r-- | views/pages.py | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/views/pages.py b/views/pages.py index 1babd7b..3a8b57d 100644 --- a/views/pages.py +++ b/views/pages.py @@ -27,12 +27,22 @@ logger = logging.getLogger(__name__) class SearchForm(forms.Form): - keyword = forms.CharField(max_length=100, + target = forms.CharField(label='', help_text=None, + widget=forms.Select( + choices=(('Subject', 'Subject'), + ('Content', 'Content'), + ('SubjectContent', 'Subject & Content'), + ('From', 'From')) + ) + ) + + keyword = forms.CharField(max_length=100,label='', help_text=None, widget=forms.TextInput( attrs={'placeholder': 'Search this list.'} ) ) + def index(request): t = loader.get_template('index2.html') search_form = SearchForm(auto_id=False) @@ -44,10 +54,11 @@ def index(request): c = RequestContext(request, { 'app_name': settings.APP_NAME, 'lists': list_data, - 'search_form': search_form['keyword'], + 'search_form': search_form, }) return HttpResponse(t.render(c)) + def archives(request, mlist_fqdn, year=None, month=None): # No year/month: past 32 days # year and month: find the 32 days for that month @@ -94,7 +105,7 @@ def archives(request, mlist_fqdn, year=None, month=None): 'app_name': settings.APP_NAME, 'list_name' : list_name, 'list_address': mlist_fqdn, - 'search_form': search_form['keyword'], + 'search_form': search_form, 'month': month_string, 'month_participants': len(participants), 'month_discussions': len(threads), @@ -151,7 +162,7 @@ def list(request, mlist_fqdn=None): 'app_name': settings.APP_NAME, 'list_name' : list_name, 'list_address': mlist_fqdn, - 'search_form': search_form['keyword'], + 'search_form': search_form, 'month': 'Recent activity', 'month_participants': len(participants), 'month_discussions': len(threads), @@ -190,7 +201,7 @@ def _search_results_page(request, mlist_fqdn, query_string, search_type): 'app_name': settings.APP_NAME, 'list_name' : list_name, 'list_address': mlist_fqdn, - 'search_form': search_form['keyword'], + 'search_form': search_form, 'month': search_type, 'month_participants': len(participants), 'month_discussions': len(threads), @@ -208,11 +219,21 @@ def search(request, mlist_fqdn): return HttpResponseRedirect(url) -def search_keyword(request, mlist_fqdn, keyword=None): +def search_keyword(request, mlist_fqdn, keyword=None, target=None): if not keyword: keyword = request.GET.get('keyword') + if not target: + target = request.GET.get('target') + if not target: + target = 'Subject' regex = '.*%s.*' % keyword - query_string = {'Subject': re.compile(regex, re.IGNORECASE)} + if target == 'SubjectContent': + query_string = {'$or' : [ + {'Subject': re.compile(regex, re.IGNORECASE)}, + {'Content': re.compile(regex, re.IGNORECASE)} + ]} + else: + query_string = {target.capitalize(): re.compile(regex, re.IGNORECASE)} return _search_results_page(request, mlist_fqdn, query_string, 'Search') |