Missing logos.
[wolnelektury.git] / src / search / forms.py
index 176c73e..a4587d7 100644 (file)
@@ -1,5 +1,5 @@
-# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
 #
 from django.apps import apps
 from django.conf import settings
 #
 from django.apps import apps
 from django.conf import settings
@@ -10,57 +10,42 @@ from catalogue.constants import LANGUAGES_3TO2
 import catalogue.models
 import pdcounter.models
 import picture.models
 import catalogue.models
 import pdcounter.models
 import picture.models
-from .fields import JQueryAutoCompleteSearchField, InlineRadioWidget
+from .fields import InlineRadioWidget
 from .utils import UnaccentSearchQuery, UnaccentSearchVector
 
 
 from .utils import UnaccentSearchQuery, UnaccentSearchVector
 
 
-class SearchForm(forms.Form):
-    q = JQueryAutoCompleteSearchField(label=_('Search'))
-    # {'minChars': 2, 'selectFirst': True, 'cacheLength': 50, 'matchContains': "word"})
-
-    def __init__(self, source, *args, **kwargs):
-        kwargs['auto_id'] = False
-        super(SearchForm, self).__init__(*args, **kwargs)
-        self.fields['q'].widget.attrs['id'] = 'search'
-        self.fields['q'].widget.attrs['autocomplete'] = 'off'
-        self.fields['q'].widget.attrs['data-source'] = source
-        if 'q' not in self.data:
-            self.fields['q'].widget.attrs['placeholder'] = _('title, author, epoch, kind, genre, phrase')
-
-
 class SearchFilters(forms.Form):
     q = forms.CharField(
         required=False, widget=forms.HiddenInput(),
         min_length=2, max_length=256,
     )
     format = forms.ChoiceField(required=False, choices=[
 class SearchFilters(forms.Form):
     q = forms.CharField(
         required=False, widget=forms.HiddenInput(),
         min_length=2, max_length=256,
     )
     format = forms.ChoiceField(required=False, choices=[
-        ('', 'wszystkie'),
-        ('text', 'tekst'),
-        ('audio', 'audiobook'),
-        ('daisy', 'Daisy'),
-        ('art', 'obraz'),
-        #('theme', 'motywy'),
+        ('', _('wszystkie')),
+        ('text', _('tekst')),
+        ('audio', _('audiobook')),
+        ('daisy', _('Daisy')),
+        ('art', _('obraz')),
     ], widget=InlineRadioWidget())
     lang = forms.ChoiceField(required=False)
     epoch = forms.ChoiceField(required=False)
     genre = forms.ChoiceField(required=False)
     category = forms.ChoiceField(required=False, choices=[
     ], widget=InlineRadioWidget())
     lang = forms.ChoiceField(required=False)
     epoch = forms.ChoiceField(required=False)
     genre = forms.ChoiceField(required=False)
     category = forms.ChoiceField(required=False, choices=[
-        ('', 'wszystkie'),
-        ('author', 'autor'),
-        #('translator', 'tłumacz'),
-        ('theme', 'motyw'),
-        ('genre', 'gatunek'),
-        ('book', 'tytuł'),
-        ('art', 'obraz'),
-        ('collection', 'kolekcja'),
-        ('quote', 'cytat'),
+        ('', _('wszystkie')),
+        ('author', _('autor')),
+        #('translator', _('tłumacz')),
+        ('theme', _('motyw')),
+        ('genre', _('gatunek')),
+        ('book', _('tytuł')),
+        ('art', _('obraz')),
+        ('collection', _('kolekcja')),
+        ('quote', _('cytat')),
     ], widget=InlineRadioWidget())
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
 
         langs = dict(settings.LANGUAGES)
     ], widget=InlineRadioWidget())
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
 
         langs = dict(settings.LANGUAGES)
-        self.fields['lang'].choices = [('', 'wszystkie')] + [
+        self.fields['lang'].choices = [('', _('wszystkie'))] + [
             (
                 b,
                 langs.get(LANGUAGES_3TO2.get(b, b), b)
             (
                 b,
                 langs.get(LANGUAGES_3TO2.get(b, b), b)
@@ -69,11 +54,11 @@ class SearchFilters(forms.Form):
                     'language', flat=True
             ).distinct().order_by()
         ]
                     'language', flat=True
             ).distinct().order_by()
         ]
-        self.fields['epoch'].choices = [('', 'wszystkie')] + [
+        self.fields['epoch'].choices = [('', _('wszystkie'))] + [
             (b.slug, b.name)
             for b in catalogue.models.Tag.objects.filter(category='epoch')
         ]
             (b.slug, b.name)
             for b in catalogue.models.Tag.objects.filter(category='epoch')
         ]
-        self.fields['genre'].choices = [('', 'wszystkie')] + [
+        self.fields['genre'].choices = [('', _('wszystkie'))] + [
             (b.slug, b.name)
             for b in catalogue.models.Tag.objects.filter(category='genre')
         ]
             (b.slug, b.name)
             for b in catalogue.models.Tag.objects.filter(category='genre')
         ]
@@ -158,8 +143,8 @@ class SearchFilters(forms.Form):
     def results(self):
         qs = self.get_querysets()
         query = self.cleaned_data['q']
     def results(self):
         qs = self.get_querysets()
         query = self.cleaned_data['q']
-        squery = UnaccentSearchQuery(query, config='polish')
-        query = SearchQuery(query, config='polish')
+        squery = UnaccentSearchQuery(query, config=settings.SEARCH_CONFIG)
+        query = SearchQuery(query, config=settings.SEARCH_CONFIG)
         books = qs['book'].annotate(
             search_vector=UnaccentSearchVector('title')
         ).filter(search_vector=squery)
         books = qs['book'].annotate(
             search_vector=UnaccentSearchVector('title')
         ).filter(search_vector=squery)
@@ -169,7 +154,7 @@ class SearchFilters(forms.Form):
                     headline=SearchHeadline(
                         'text',
                         query,
                     headline=SearchHeadline(
                         'text',
                         query,
-                        config='polish',
+                        config=settings.SEARCH_CONFIG,
                         start_sel='<strong>',
                         stop_sel='</strong>',
                     )
                         start_sel='<strong>',
                         stop_sel='</strong>',
                     )