X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/fddf0ef87d70d72448586e1cdd844c795fdea5c5..1f44d5cf5f461e238a707c9779bb29af5b12d2c2:/apps/catalogue/templatetags/catalogue_tags.py diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index 36a015ae6..c1d318afd 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -61,9 +61,16 @@ def simple_title(tags): return capfirst(', '.join(title)) +def book_stub_title(book): + return ', '.join((book.author, book.title)) + + @register.simple_tag def book_title(book, html_links=False): - names = list(book.tags.filter(category='author')) + try: + names = list(book.tags.filter(category='author')) + except AttributeError: + return book_stub_title(book) books = [] while book: @@ -148,6 +155,18 @@ def title_from_tags(tags): return capfirst(title) +@register.simple_tag +def book_tree(book_list, books_by_parent): + text = "".join("
  • %s%s
  • " % ( + book.get_absolute_url(), book.title, book_tree(books_by_parent.get(book, ()), books_by_parent) + ) for book in book_list) + + if text: + return "
      %s
    " % text + else: + return '' + + @register.simple_tag def user_creation_form(): return RegistrationForm(prefix='registration').as_ul() @@ -253,6 +272,7 @@ def tag_list(tags, choices=None): @register.inclusion_tag('catalogue/folded_tag_list.html') def folded_tag_list(tags, choices=None): + tags = [tag for tag in tags if tag.count] if choices is None: choices = [] some_tags_hidden = False