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 dictionary.models import Note
6 from django.views.generic.list import ListView
7 from django.db.models import Count
10 class NotesView(ListView):
11 def get_queryset(self):
12 self.letters = ["0-9"] + [chr(a) for a in range(ord('a'), ord('z')+1)]
13 self.letter = self.request.GET.get('ltr')
15 self.qualifiers = Note.objects.order_by('qualifier').filter(qualifier__startswith='f').values_list(
16 'qualifier', flat=True).distinct()
17 self.qualifier = self.request.GET.get('qual')
19 self.languages = Note.objects.order_by('language').values_list(
20 'language', flat=True).distinct()
21 self.language = self.request.GET.get('lang')
23 self.fn_types = Note.objects.order_by('fn_type').values_list(
24 'fn_type', flat=True).distinct()
25 self.fn_type = self.request.GET.get('type')
27 objects = Note.objects.select_related('book').all()
29 if self.letter == "0-9":
30 objects = objects.filter(sort_key__regex=r"^[0-9]")
32 objects = objects.filter(sort_key__startswith=self.letter)
35 objects = objects.filter(qualifier=self.qualifier)
38 objects = objects.filter(language=self.language)
41 objects = objects.filter(fn_type=self.fn_type)
45 # TODO: wewn. wyszukiwarka, czy wg definiendum?
48 def get_context_data(self, **kwargs):
49 context = super(NotesView, self).get_context_data(**kwargs)
50 context['letters'] = self.letters
51 context['letter'] = self.letter
52 context['qualifiers'] = self.qualifiers
53 context['qualifier'] = self.qualifier
54 context['languages'] = self.languages
55 context['language'] = self.language
56 context['fn_types'] = self.fn_types
57 context['fn_type'] = self.fn_type