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