Code layout change.
[wolnelektury.git] / src / search / forms.py
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.
4 #
5 from django import forms
6 from django.utils.translation import ugettext_lazy as _
7
8 from search.fields import JQueryAutoCompleteSearchField
9
10
11 class SearchForm(forms.Form):
12     q = JQueryAutoCompleteSearchField(label=_('Search'))  # {'minChars': 2, 'selectFirst': True, 'cacheLength': 50, 'matchContains': "word"})
13
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['placeholder'] = _('title, author, theme/topic, epoch, kind, genre, phrase')