enable cojaczytam form
[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.template import RequestContext
7 from django.shortcuts import render_to_response, get_object_or_404
8 from django.views.decorators import cache
9 from suggest.forms import PublishingSuggestForm
10 from . import models
11
12
13 @cache.never_cache
14 def book_stub_detail(request, slug):
15     book = get_object_or_404(models.BookStub, slug=slug)
16     if book.pd and not book.in_pd():
17         pd_counter = datetime(book.pd, 1, 1)
18     else:
19         pd_counter = None
20
21     form = PublishingSuggestForm(initial={"books": u"%s — %s, \n" % (book.author, book.title)})
22
23     return render_to_response('pdcounter/book_stub_detail.html', {
24         'book': book,
25         'pd_counter': pd_counter,
26         'form': form,
27     }, context_instance=RequestContext(request))
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     return render_to_response('pdcounter/author_detail.html', {
41         'author': author,
42         'pd_counter': pd_counter,
43         'form': form,
44     }, context_instance=RequestContext(request))