X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/6f2ae8587bd74b8d5d4f89170ef72209af2f9a1f..125dc5790b7ee10a6ccef6874efa84d60baf0f4e:/apps/catalogue/templatetags/catalogue_tags.py diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index fa7849538..c1d318afd 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -61,15 +61,22 @@ 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: books.append(book) book = book.parent - names.extend(reversed(books[::-1])) + names.extend(reversed(books)) if html_links: names = ['%s' % (tag.get_absolute_url(), tag.name) for tag in names] @@ -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