X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ddaff853c515ef7d188523d9ef17d271901dd581..e7c8c7e1fd0fe2eb867b26ae205b75822204a45f:/apps/dictionary/views.py diff --git a/apps/dictionary/views.py b/apps/dictionary/views.py index 4208d9b4c..fa9712dda 100755 --- a/apps/dictionary/views.py +++ b/apps/dictionary/views.py @@ -4,22 +4,55 @@ # from dictionary.models import Note from django.views.generic.list import ListView +from django.db.models import Count class NotesView(ListView): def get_queryset(self): self.letters = ["0-9"] + [chr(a) for a in range(ord('a'), ord('z')+1)] - self.letter = self.kwargs.get('letter') + self.letter = self.request.GET.get('ltr') + + self.qualifiers = Note.objects.order_by('qualifier').filter(qualifier__startswith='f').values_list( + 'qualifier', flat=True).distinct() + self.qualifier = self.request.GET.get('qual') + + self.languages = Note.objects.order_by('language').values_list( + 'language', flat=True).distinct() + self.language = self.request.GET.get('lang') + + self.fn_types = Note.objects.order_by('fn_type').values_list( + 'fn_type', flat=True).distinct() + self.fn_type = self.request.GET.get('type') + + objects = Note.objects.select_related('book').all() - objects = Note.objects.all() if self.letter == "0-9": objects = objects.filter(sort_key__regex=r"^[0-9]") elif self.letter: objects = objects.filter(sort_key__startswith=self.letter) + + if self.qualifier: + objects = objects.filter(qualifier=self.qualifier) + + if self.language: + objects = objects.filter(language=self.language) + + if self.fn_type: + objects = objects.filter(fn_type=self.fn_type) + return objects + # TODO: wewn. wyszukiwarka, czy wg definiendum? + # TODO: filtr języka + def get_context_data(self, **kwargs): context = super(NotesView, self).get_context_data(**kwargs) - context['letter'] = self.letter context['letters'] = self.letters + context['letter'] = self.letter + context['qualifiers'] = self.qualifiers + context['qualifier'] = self.qualifier + context['languages'] = self.languages + context['language'] = self.language + context['fn_types'] = self.fn_types + context['fn_type'] = self.fn_type return context