Fix for heads.
[wolnelektury.git] / src / pdcounter / views.py
1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from datetime import datetime
5 from django.shortcuts import render, get_object_or_404
6 from django.views.decorators import cache
7 from suggest.forms import PublishingSuggestForm
8 from . import models
9
10
11 @cache.never_cache
12 def book_stub_detail(request, slug):
13     book = get_object_or_404(models.BookStub, slug=slug)
14     if book.pd and not book.in_pd():
15         pd_counter = datetime(book.pd, 1, 1)
16     else:
17         pd_counter = None
18
19     form = PublishingSuggestForm(initial={"books": "%s — %s, \n" % (book.author, book.title)})
20
21     if request.EXPERIMENTS['layout'].value:
22         template_name = 'pdcounter/2022/book_detail.html'
23     else:
24         template_name = 'pdcounter/book_stub_detail.html'
25
26     return render(request, template_name, {
27         'book': book,
28         'pd_counter': pd_counter,
29         'form': form,
30     })
31
32
33 @cache.never_cache
34 def author_detail(request, slug):
35     author = get_object_or_404(models.Author, slug=slug)
36     if not author.alive():
37         pd_counter = datetime(author.goes_to_pd(), 1, 1)
38     else:
39         pd_counter = None
40
41     form = PublishingSuggestForm(initial={"books": author.name + ", \n"})
42
43     if request.EXPERIMENTS['layout'].value:
44         template_name = 'pdcounter/2022/author_detail.html'
45     else:
46         template_name = 'pdcounter/author_detail.html'
47
48     return render(request, template_name, {
49         'author': author,
50         'pd_counter': pd_counter,
51         'form': form,
52     })