X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/04f567d3dcf63ec88484ba25a178c6eb336ea04e..16926672fd1edefa55acf4159f8b5d9b6aef5b8a:/src/catalogue/views.py diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 8f1ca2f00..47706240c 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -182,30 +182,32 @@ def tagged_object_list(request, tags='', list_type='default'): pk__in=tags_pks), ) else: - if tags: - all_books = Book.tagged.with_all(tags) - else: - all_books = Book.objects.filter(parent=None) - if shelf_is_set: + if audiobooks: + all_books = Book.objects.filter(media__type__in=('mp3', 'ogg')).distinct() + if tags: + all_books = Book.tagged.with_all(tags, all_books) objects = all_books + # there's never only the daisy audiobook + daisy = objects.filter(media__type='daisy').distinct().order_by('sort_key_author', 'sort_key') related_book_tags = Tag.objects.usage_for_queryset( objects, counts=True).exclude( category='set').exclude(pk__in=tags_pks) else: if tags: - objects = Book.tagged_top_level(tags) + all_books = Book.tagged.with_all(tags) else: + all_books = Book.objects.filter(parent=None) + if shelf_is_set: objects = all_books - # WTF: was outside if, overwriting value assigned if shelf_is_set - related_book_tags = get_top_level_related_tags(tags) - - if audiobooks: - if objects != all_books: - all_books = all_books.filter(media__type__in=('mp3', 'ogg')).distinct() - objects = objects.filter(media__type__in=('mp3', 'ogg')).distinct() + related_book_tags = Tag.objects.usage_for_queryset( + objects, counts=True).exclude( + category='set').exclude(pk__in=tags_pks) else: - all_books = objects = objects.filter(media__type__in=('mp3', 'ogg')).distinct() - daisy = objects.filter(media__type='daisy').distinct().order_by('sort_key_author', 'sort_key') + if tags: + objects = Book.tagged_top_level(tags) + else: + objects = all_books + related_book_tags = get_top_level_related_tags(tags) fragments = Fragment.objects.filter(book__in=all_books) @@ -228,7 +230,13 @@ def tagged_object_list(request, tags='', list_type='default'): if tag.category in ('theme', 'thing') and ( PictureArea.tagged.with_any([tag]).exists() or Picture.tagged.with_any([tag]).exists()): - return redirect('tagged_object_list_gallery', raw_tags, permanent=False) + return redirect('tagged_object_list_gallery', raw_tags) + + # this is becoming more and more hacky + if list_type == 'default' and not tags: + last_published = Book.objects.exclude(cover_thumb='').filter(parent=None).order_by('-created_at')[:20] + else: + last_published = None return render_to_response( 'catalogue/tagged_object_list.html', @@ -244,6 +252,7 @@ def tagged_object_list(request, tags='', list_type='default'): 'best': best, 'list_type': list_type, 'daisy': daisy, + 'last_published': last_published, }, context_instance=RequestContext(request))