X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/4bacdff72c8044d25066ff95719543a763844e11..HEAD:/src/catalogue/templatetags/catalogue_tags.py
diff --git a/src/catalogue/templatetags/catalogue_tags.py b/src/catalogue/templatetags/catalogue_tags.py
index b45fc50cf..c9e776c8f 100644
--- a/src/catalogue/templatetags/catalogue_tags.py
+++ b/src/catalogue/templatetags/catalogue_tags.py
@@ -1,5 +1,5 @@
-# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
#
from random import randint, random
from urllib.parse import urlparse
@@ -43,13 +43,13 @@ def html_title_from_tags(tags):
return title_from_tags(tags)
template = Template("{{ category }}: {{ tag.name }}")
return mark_safe(capfirst(",
".join(
- template.render(Context({'tag': tag, 'category': _(tag.category)})) for tag in tags)))
+ template.render(Context({'tag': tag, 'category': tag.get_category_display()})) for tag in tags)))
def simple_title(tags):
title = []
for tag in tags:
- title.append("%s: %s" % (_(tag.category), tag.name))
+ title.append("%s: %s" % (tag.get_category_display(), tag.name))
return capfirst(', '.join(title))
@@ -151,19 +151,6 @@ def book_tree(book_list, books_by_parent):
return ''
-@register.simple_tag
-def audiobook_tree(book_list, books_by_parent):
- text = "".join("
%s%s" % (
- reverse("book_player", args=[book.slug]), book.title,
- audiobook_tree(books_by_parent.get(book, ()), books_by_parent)
- ) for book in book_list)
-
- if text:
- return mark_safe("%s
" % text)
- else:
- return ''
-
-
@register.simple_tag
def book_tree_texml(book_list, books_by_parent, depth=1):
return mark_safe("".join("""
@@ -322,16 +309,6 @@ def tag_list(tags, choices=None, category=None, list_type='books'):
}
-@register.inclusion_tag('catalogue/inline_tag_list.html')
-def inline_tag_list(tags, choices=None, category=None, list_type='books'):
- return tag_list(tags, choices, category, list_type)
-
-
-@register.inclusion_tag('catalogue/collection_list.html')
-def collection_list(collections):
- return {'collections': collections}
-
-
@register.inclusion_tag('catalogue/book_info.html')
def book_info(book):
return {
@@ -340,12 +317,6 @@ def book_info(book):
}
-@register.inclusion_tag('catalogue/work-list.html', takes_context=True)
-def work_list(context, object_list):
- request = context.get('request')
- return {'object_list': object_list, 'request': request}
-
-
@register.inclusion_tag('catalogue/plain_list.html', takes_context=True)
def plain_list(context, object_list, with_initials=True, by_author=False, choice=None, book=None, list_type='books',
paged=True, initial_blocks=False):
@@ -424,7 +395,18 @@ def related_books_2022(book=None, picture=None, limit=4, taken=0):
books = Book.tagged.related_to(instance, books_qs)[:max_books]
return books
-
+
+@register.simple_tag
+def related_pictures_2022(book=None, picture=None, limit=4, taken=0):
+ limit -= taken
+ max_books = limit
+
+ books_qs = Picture.objects.all()
+ instance = book or picture
+ books = Picture.tagged.related_to(instance, books_qs)[:max_books]
+
+ return books
+
@register.simple_tag
def download_audio(book, daisy=True, mp3=True):
@@ -470,11 +452,6 @@ def license_locative(license_url, default):
return LICENSES.get(license_url, {}).get('locative', default)
-@register.filter
-def class_name(obj):
- return obj.__class__.__name__
-
-
@register.simple_tag
def source_name(url):
url = url.lstrip()
@@ -535,7 +512,7 @@ def status(book, user):
@register.inclusion_tag('catalogue/snippets/content_warning.html')
def content_warning(book):
warnings_def = {
- 'wulgaryzmy': _('vulgar language'),
+ 'wulgaryzmy': _('wulgaryzmy'),
}
warnings = book.get_extra_info_json().get('content_warnings', [])
warnings = sorted(
@@ -550,6 +527,8 @@ def content_warning(book):
@register.inclusion_tag('catalogue/preview_ad.html', takes_context=True)
def preview_ad(context):
book = Book.objects.filter(parent=None, preview=True).first()
+ if book is None:
+ return {}
return {
'accessible': book.is_accessible_to(context['request'].user),
'book': book,
@@ -558,6 +537,8 @@ def preview_ad(context):
@register.inclusion_tag('catalogue/preview_ad_homepage.html', takes_context=True)
def preview_ad_homepage(context):
book = Book.objects.filter(parent=None, preview=True).first()
+ if book is None:
+ return {}
return {
'accessible': book.is_accessible_to(context['request'].user),
'book': book,