From aec703e4334f431339fb60ab5cf773eed4cd03f7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20St=C4=99pniowski?= Date: Wed, 24 Sep 2008 10:49:57 +0200 Subject: [PATCH] Children book formats are added to ZIP archive for shelf. --- apps/catalogue/views.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index f574c13fa..b73552ed6 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -214,7 +214,18 @@ def download_shelf(request, slug): # Create a ZIP archive temp = temp = tempfile.TemporaryFile() archive = zipfile.ZipFile(temp, 'w') - for book in models.Book.tagged.with_all(shelf): + + # Collect all books to include in ZIP archive + def collect_books(books): + result = [] + for book in books: + if len(book.children.all()) == 0: + result.append(book) + else: + result += collect_books(book.children.all()) + return result + + for book in collect_books(models.Book.tagged.with_all(shelf)): if book.pdf_file: filename = book.pdf_file.path archive.write(filename, str('%s.pdf' % book.slug)) -- 2.20.1