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
8 from rest_framework.generics import ListAPIView
9 from rest_framework.filters import SearchFilter
10 from rest_framework import serializers
13 class CatalogueView(TemplateView):
14 template_name = "catalogue/catalogue.html"
16 def get_context_data(self):
17 ctx = super().get_context_data()
18 ctx["authors"] = models.Author.objects.all().prefetch_related('book_set__book_set', 'translated_book_set__book_set')
23 class AuthorView(TemplateView):
25 template_name = "catalogue/author_detail.html"
27 def get_context_data(self, slug):
28 ctx = super().get_context_data()
29 authors = models.Author.objects.filter(slug=slug).prefetch_related(
31 Prefetch("translated_book_set"),
33 ctx["author"] = authors.first()
37 class BookView(DetailView):
41 class TermSearchFilter(SearchFilter):
45 class Terms(ListAPIView):
46 filter_backends = [TermSearchFilter]
47 search_fields = ['name']
49 class serializer_class(serializers.Serializer):
50 label = serializers.CharField(source='name')
53 class EpochTerms(Terms):
54 queryset = models.Epoch.objects.all()
55 class KindTerms(Terms):
56 queryset = models.Kind.objects.all()
57 class GenreTerms(Terms):
58 queryset = models.Genre.objects.all()