-# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
#
import zipfile
from django.core.management.base import BaseCommand
parser.add_argument(
'-e', '--exclude', dest='exclude', metavar='SLUG,...',
help='Exclude specific books by slug')
+ parser.add_argument(
+ '--top-level', dest='top_level', action='store_true')
parser.add_argument('ftype', metavar='|'.join(Book.formats))
parser.add_argument('path', metavar='output_path.zip')
tags = options.get('tags')
include = options.get('include')
exclude = options.get('exclude')
+ top_level = options.get('top_level')
if ftype in Book.formats:
field = "%s_file" % ftype
if tags:
books += list(Book.tagged.with_all(Tag.objects.filter(slug__in=tags.split(','))).only('slug', field))
elif not include:
- books = list(Book.objects.all().only('slug', field))
+ books = Book.objects.all()
+ if top_level:
+ books = books.filter(parent=None)
+ books = list(books.only('slug', field))
if exclude:
books = [book for book in books if book.slug not in exclude.split(',')]