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