X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/0c3e8f92c425a22c1b9da737db89977d31312353..e7c8c7e1fd0fe2eb867b26ae205b75822204a45f:/apps/dictionary/views.py?ds=inline diff --git a/apps/dictionary/views.py b/apps/dictionary/views.py index a2a814b03..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) - return ListView.get_queryset(self) + + 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