1 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django.db.models import Prefetch
5 from django.views.generic import DetailView, TemplateView
7 import documents.models
10 class CatalogueView(TemplateView):
11 template_name = "catalogue/catalogue.html"
13 def get_context_data(self):
14 ctx = super().get_context_data()
15 documents_books_queryset = models.Book.objects.prefetch_unrelated(
16 "document_books", "slug", documents.models.Book, "dc_slug"
18 ctx["authors"] = models.Author.objects.all().prefetch_related(
19 Prefetch("book_set", queryset=documents_books_queryset),
20 Prefetch("translated_book_set", queryset=documents_books_queryset),
25 class AuthorView(TemplateView):
27 template_name = "catalogue/author_detail.html"
29 def get_context_data(self, slug):
30 ctx = super().get_context_data()
31 documents_books_queryset = models.Book.objects.prefetch_unrelated(
32 "document_books", "slug", documents.models.Book, "dc_slug"
34 authors = models.Author.objects.filter(slug=slug).prefetch_related(
35 Prefetch("book_set", queryset=documents_books_queryset),
36 Prefetch("translated_book_set", queryset=documents_books_queryset),
38 ctx["author"] = authors.first()
42 class BookView(DetailView):