2022-01-18 20:28:59 +00:00
|
|
|
""" template filters """
|
|
|
|
from django import template
|
|
|
|
|
|
|
|
|
|
|
|
register = template.Library()
|
|
|
|
|
|
|
|
|
|
|
|
@register.filter(name="book_description")
|
|
|
|
def get_book_description(book):
|
|
|
|
"""use the work's text if the book doesn't have it"""
|
2022-08-07 20:26:05 +00:00
|
|
|
if book.description:
|
|
|
|
return book.description
|
|
|
|
if book.parent_work:
|
|
|
|
# this shoud always be true
|
|
|
|
return book.parent_work.description
|
|
|
|
return None
|
2022-01-18 20:28:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
@register.simple_tag(takes_context=False)
|
|
|
|
def get_book_file_links(book):
|
|
|
|
"""links for a book"""
|
|
|
|
return book.file_links.filter(domain__status="approved")
|
2022-11-02 01:04:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
@register.filter(name="author_edition")
|
|
|
|
def get_author_edition(book, author):
|
|
|
|
"""default edition for a book on the author page"""
|
|
|
|
return book.author_edition(author)
|