}
+@register.simple_tag
+def related_books_2022(instance, limit=4, taken=0):
+ limit -= taken
+ max_books = limit
+
+ books_qs = Book.objects.filter(findable=True)
+ books_qs = books_qs.exclude(common_slug=instance.common_slug).exclude(ancestor=instance)
+ books = Book.tagged.related_to(instance, books_qs)[:max_books]
+
+ return books
+
+
@register.simple_tag
def download_audio(book, daisy=True, mp3=True):
links = []
if daisy and book.has_media('daisy'):
for dsy in book.get_media('daisy'):
links.append("<a href='%s'>%s</a>" % (dsy.file.url, BookMedia.formats['daisy'].name))
+ if daisy and book.has_media('audio.epub'):
+ for dsy in book.get_media('audio.epub'):
+ links.append("<a href='%s'>%s</a>" % (dsy.file.url, BookMedia.formats['audio.epub'].name))
return mark_safe("".join(links))
}
+@register.simple_tag
+def license_locative(license_url, default):
+ return LICENSES.get(license_url, {}).get('locative', default)
+
+
@register.filter
def class_name(obj):
return obj.__class__.__name__
def status(book, user):
if not book.preview:
return 'open'
- elif Membership.is_active_for(user):
+ elif book.is_accessible_to(user):
return 'preview'
else:
return 'closed'
+
+
+@register.inclusion_tag('catalogue/snippets/content_warning.html')
+def content_warning(book):
+ warnings_def = {
+ 'wulgaryzmy': _('vulgar language'),
+ }
+ warnings = book.get_extra_info_json().get('content_warnings', [])
+ warnings = sorted(
+ warnings_def.get(w, w)
+ for w in warnings
+ )
+ return {
+ "warnings": warnings
+ }
+
+
+@register.inclusion_tag('catalogue/preview_ad.html', takes_context=True)
+def preview_ad(context):
+ book = Book.objects.filter(preview=True).first()
+ return {
+ 'accessible': book.is_accessible_to(context['request'].user),
+ 'book': book,
+ }