X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/60b06883b6d5a336ef47c01103ec1ce25aafae69..e6fc1b86fcdb4f99c00d4218fcaa5eab6f64c4cb:/apps/dictionary/views.py?ds=sidebyside diff --git a/apps/dictionary/views.py b/apps/dictionary/views.py index e12006366..76c89cd85 100755 --- a/apps/dictionary/views.py +++ b/apps/dictionary/views.py @@ -2,17 +2,24 @@ # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # -from django.views.generic.list_detail import object_list -from catalogue.forms import SearchForm from dictionary.models import Note +from django.views.generic.list import ListView -def letter_notes(request, letter=None): - form = SearchForm() - letters = ["0-9"] + [chr(a) for a in range(ord('a'), ord('z')+1)] - objects = Note.objects.all() - if letter == "0-9": - objects = objects.filter(sort_key__regex=r"^[0-9]") - elif letter: - objects = objects.filter(sort_key__startswith=letter) - return object_list(request, queryset=objects, extra_context=locals()) +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') + + objects = Note.objects.select_related('book').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 objects + + def get_context_data(self, **kwargs): + context = super(NotesView, self).get_context_data(**kwargs) + context['letter'] = self.letter + context['letters'] = self.letters + return context