X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/2856ae6ae36213ca7997366e0c7790e3c855e62f..da000570285d53adef7dd9d799ee49398e0e370b:/apps/catalogue/templatetags/catalogue_tags.py diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index 8c073c137..c9bf3dda2 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -16,7 +16,7 @@ from django.utils.translation import ugettext as _ from catalogue.utils import split_tags, related_tag_name as _related_tag_name from catalogue.models import Book, BookMedia, Fragment, Tag -from catalogue.constants import LICENSES +from catalogue.constants import LICENSES, LANGUAGES_3TO2 register = template.Library() @@ -335,6 +335,7 @@ def book_wide(context, book): 'hide_about': hide_about, 'themes': book_themes, 'request': context.get('request'), + 'show_lang': book.language_code() != settings.LANGUAGE_CODE, } @@ -345,24 +346,28 @@ def book_short(context, book): 'main_link': book.get_absolute_url(), 'related': book.related_info(), 'request': context.get('request'), + 'show_lang': book.language_code() != settings.LANGUAGE_CODE, } @register.inclusion_tag('catalogue/book_mini_box.html') -def book_mini(book): +def book_mini(book, with_link=True): author_str = ", ".join(related_tag_name(tag) - for tag in book.related_info()['tags']['author']) + for tag in book.related_info()['tags'].get('author', ())) return { 'book': book, 'author_str': author_str, + 'with_link': with_link, + 'show_lang': book.language_code() != settings.LANGUAGE_CODE, } @register.inclusion_tag('catalogue/work-list.html', takes_context=True) def work_list(context, object_list): request = context.get('request') - if object_list: - object_type = type(object_list[0]).__name__ + for obj in object_list: + obj.object_type = type(obj).__name__ + return locals() @@ -383,17 +388,14 @@ def fragment_promo(arg=None): @register.inclusion_tag('catalogue/related_books.html') -def related_books(book, limit=6, random=1): +def related_books(book, limit=6, random=1, taken=0): + limit = limit - taken cache_key = "catalogue.related_books.%d.%d" % (book.id, limit - random) related = cache.get(cache_key) if related is None: - related = list(Book.objects.filter( - common_slug=book.common_slug).exclude(pk=book.pk)[:limit]) - limit -= len(related) - if limit > random: - related += Book.tagged.related_to(book, - Book.objects.exclude(common_slug=book.common_slug), - ignore_by_tag=book.book_tag())[:limit-random] + related = Book.tagged.related_to(book, + Book.objects.exclude(common_slug=book.common_slug), + ignore_by_tag=book.book_tag())[:limit-random] cache.set(cache_key, related, 1800) if random: random_books = Book.objects.exclude( @@ -416,7 +418,7 @@ def catalogue_menu(): ('genre', _('Genres'), 'gatunki'), ('kind', _('Kinds'), 'rodzaje'), ('epoch', _('Epochs'), 'epoki'), - ('theme', _('Themes'), 'autorzy'), + ('theme', _('Themes'), 'motywy'), ]} @@ -468,3 +470,9 @@ def license_icon(license_url): @register.simple_tag def related_tag_name(tag, lang=None): return _related_tag_name(tag, lang) + + +@register.simple_tag +def class_name(obj): + return obj.__class__.__name__ +