ca61f161f75cbd8b31a5c226b65f3dc859e8977a
[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     template_name = 'pdcounter/book_detail.html'
22
23     return render(request, template_name, {
24         'book': book,
25         'pd_counter': pd_counter,
26         'form': form,
27     })
28
29
30 @cache.never_cache
31 def author_detail(request, slug):
32     author = get_object_or_404(models.Author, slug=slug)
33     if not author.alive():
34         pd_counter = datetime(author.goes_to_pd(), 1, 1)
35     else:
36         pd_counter = None
37
38     form = PublishingSuggestForm(initial={"books": author.name + ", \n"})
39
40     template_name = 'pdcounter/author_detail.html'
41
42     return render(request, template_name, {
43         'author': author,
44         'pd_counter': pd_counter,
45         'form': form,
46     })