Don't cache whole pages, cache what's taking time.
[wolnelektury.git] / apps / dictionary / views.py
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.
4 #
5 from dictionary.models import Note
6 from django.views.generic.list import ListView
7
8
9 class NotesView(ListView):
10     def get_queryset(self):
11         self.letters = ["0-9"] + [chr(a) for a in range(ord('a'), ord('z')+1)]
12         self.letter = self.kwargs.get('letter')
13
14         objects = Note.objects.select_related('book').all()
15         if self.letter == "0-9":
16             objects = objects.filter(sort_key__regex=r"^[0-9]")
17         elif self.letter:
18             objects = objects.filter(sort_key__startswith=self.letter)
19         return objects
20
21     def get_context_data(self, **kwargs):
22         context = super(NotesView, self).get_context_data(**kwargs)
23         context['letter'] = self.letter
24         context['letters'] = self.letters
25         return context