staff_required = user_passes_test(lambda user: user.is_staff)
-def catalogue(request, as_json=False):
- books = models.Book.objects.filter(parent=None)
- pictures = Picture.objects.all()
- collections = models.Collection.objects.all()
- return render(request, 'catalogue/catalogue.html', locals())
+def catalogue(request):
+ return render(request, 'catalogue/catalogue.html', {
+ 'books': models.Book.objects.filter(parent=None).order_by('sort_key_author', 'sort_key'),
+ 'pictures': Picture.objects.order_by('sort_key_author', 'sort_key'),
+ 'collections': models.Collection.objects.all(),
+ })
def book_list(request, filter=None, get_filter=None, template_name='catalogue/book_list.html',
for tag in books_by_author:
if books_by_author[tag]:
books_nav.setdefault(tag.sort_key[0], []).append(tag)
- rendered_nav = render_to_string(nav_template_name, locals())
- rendered_book_list = render_to_string(list_template_name, locals())
- return render_to_response(template_name, locals(), context_instance=RequestContext(request))
+ # WTF: dlaczego nie include?
+ return render_to_response(template_name, {
+ 'rendered_nav': render_to_string(nav_template_name, {'books_nav': books_nav}),
+ 'rendered_book_list': render_to_string(list_template_name, {
+ 'books_by_author': books_by_author,
+ 'orphans': orphans,
+ 'books_by_parent': books_by_parent,
+ })
+ }, context_instance=RequestContext(request))
def audiobook_list(request):
- books = models.Book.objects.filter(Q(media__type='mp3') | Q(media__type='ogg')).distinct()
+ books = models.Book.objects.filter(media__type__in=('mp3', 'ogg')).distinct().order_by(
+ 'sort_key_author', 'sort_key')
books = list(books)
if len(books) > 3:
best = random.sample(books, 3)
else:
best = books
- daisy = models.Book.objects.filter(media__type='daisy').distinct()
+ daisy = models.Book.objects.filter(media__type='daisy').distinct().order_by('sort_key_author', 'sort_key')
return render(request, 'catalogue/audiobook_list.html', {
'books': books,
raise Http404
else:
if tags:
- objects = Picture.tagged.with_all(tags).order_by(
- 'sort_key_author', 'title')
+ objects = Picture.tagged.with_all(tags)
else:
- objects = Picture.objects.all().order_by(
- 'sort_key_author', 'title')
+ objects = Picture.objects.all()
areas = PictureArea.objects.filter(picture__in=objects)
categories = split_tags(
models.Tag.objects.usage_for_queryset(
else:
all_books = models.Book.objects.filter(parent=None)
if shelf_is_set:
- objects = all_books.order_by('sort_key_author', 'title')
+ objects = all_books
related_book_tags = models.Tag.objects.usage_for_queryset(
objects, counts=True).exclude(
category='set').exclude(pk__in=tags_pks)
else:
if tags:
- objects = models.Book.tagged_top_level(tags).order_by(
- 'sort_key_author', 'title')
+ objects = models.Book.tagged_top_level(tags)
else:
- objects = all_books.order_by('sort_key_author', 'title')
+ objects = all_books
# WTF: was outside if, overwriting value assigned if shelf_is_set
related_book_tags = get_top_level_related_tags(tags)
fragments, counts=True).filter(
category='theme').exclude(pk__in=tags_pks),
)
+ objects = objects.order_by('sort_key_author', 'sort_key')
objects = list(objects)
if len(objects) > 3:
fragments = models.Fragment.tagged.with_all([theme]).filter(
Q(book=book) | Q(book__ancestor=book))
- return render_to_response('catalogue/book_fragments.html', locals(), context_instance=RequestContext(request))
+ return render_to_response('catalogue/book_fragments.html', {
+ 'book': book,
+ 'theme': theme,
+ 'fragments': fragments,
+ }, context_instance=RequestContext(request))
def book_detail(request, slug):
except models.Book.DoesNotExist:
return pdcounter_views.book_stub_detail(request, slug)
- tags = book.tags.exclude(category__in=('set', 'theme'))
- book_children = book.children.all().order_by('parent_number', 'sort_key')
- return render_to_response('catalogue/book_detail.html', locals(), context_instance=RequestContext(request))
+ return render_to_response('catalogue/book_detail.html', {
+ 'book': book,
+ 'tags': book.tags.exclude(category__in=('set', 'theme')),
+ 'book_children': book.children.all().order_by('parent_number', 'sort_key'),
+ }, context_instance=RequestContext(request))
def get_audiobooks(book):
return audiobooks, projects, have_oggs
+# używane tylko do audiobook_tree, które jest używane tylko w snippets/audiobook_list.html, które nie jest używane
def player(request, slug):
book = get_object_or_404(models.Book, slug=slug)
if not book.has_media('mp3'):
audiobooks, projects, have_oggs = get_audiobooks(book)
- extra_info = book.extra_info
+ # extra_info = book.extra_info
- return render_to_response('catalogue/player.html', locals(), context_instance=RequestContext(request))
+ return render_to_response('catalogue/player.html', {
+ 'book': book,
+ 'audiobook': '',
+ 'audiobooks': audiobooks,
+ 'projects': projects,
+ }, context_instance=RequestContext(request))
def book_text(request, slug):
if not book.has_html_file():
raise Http404
- return render_to_response('catalogue/book_text.html', locals(), context_instance=RequestContext(request))
+ return render_to_response('catalogue/book_text.html', {'book': book,}, context_instance=RequestContext(request))
# ==========
book = get_object_or_404(models.Book, id=book_id)
# set language by hand
translation.activate(lang)
- return render_to_response('catalogue/book_info.html', locals(), context_instance=RequestContext(request))
+ return render_to_response('catalogue/book_info.html', {'book': book}, context_instance=RequestContext(request))
def tag_info(request, tag_id):
else:
tags = list(get_top_level_related_tags((), categories=(category,)))
- tags = [tag for tag in tags if tag.description]
+ described_tags = [tag for tag in tags if tag.description]
- if len(tags) > 4:
- best = random.sample(tags, 4)
+ if len(described_tags) > 4:
+ best = random.sample(described_tags, 4)
else:
- best = tags
+ best = described_tags
return render(request, 'catalogue/tag_catalogue.html', {
'tags': tags,