1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django import forms
6 from django.utils.translation import ugettext_lazy as _
8 from search.fields import JQueryAutoCompleteSearchField
11 class SearchForm(forms.Form):
12 q = JQueryAutoCompleteSearchField() # {'minChars': 2, 'selectFirst': True, 'cacheLength': 50, 'matchContains': "word"})
14 def __init__(self, source, *args, **kwargs):
15 kwargs['auto_id'] = False
16 super(SearchForm, self).__init__(*args, **kwargs)
17 self.fields['q'].widget.attrs['id'] = _('search')
18 self.fields['q'].widget.attrs['autocomplete'] = 'off'
19 self.fields['q'].widget.attrs['data-source'] = source
20 if not 'q' in self.data:
21 self.fields['q'].widget.attrs['title'] = _('title, author, theme/topic, epoch, kind, genre, phrase')