Minor style fix in gallery view.
[redakcja.git] / src / catalogue / views.py
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.
3 #
4 from django.db.models import Prefetch
5 from django.views.generic import DetailView, TemplateView
6 from . import models
7 import documents.models
8
9
10 class CatalogueView(TemplateView):
11     template_name = "catalogue/catalogue.html"
12
13     def get_context_data(self):
14         ctx = super().get_context_data()
15         ctx["authors"] = models.Author.objects.all().prefetch_related('book_set__book_set', 'translated_book_set__book_set')
16
17         return ctx
18
19
20 class AuthorView(TemplateView):
21     model = models.Author
22     template_name = "catalogue/author_detail.html"
23
24     def get_context_data(self, slug):
25         ctx = super().get_context_data()
26         authors = models.Author.objects.filter(slug=slug).prefetch_related(
27             Prefetch("book_set"),
28             Prefetch("translated_book_set"),
29         )
30         ctx["author"] = authors.first()
31         return ctx
32
33
34 class BookView(DetailView):
35     model = models.Book