add field to mark books as recommended
[wolnelektury.git] / src / catalogue / management / commands / gencover.py
1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 from django.core.management.base import BaseCommand
6
7 from catalogue.models import Book
8 from librarian.cover import make_cover
9
10
11 class Command(BaseCommand):
12     def add_arguments(self, parser):
13         parser.add_argument('slug')
14         parser.add_argument('size', type=int)
15         parser.add_argument('--bleed', action='store_true')
16
17     def handle(self, *args, **options):
18         slug = options['slug']
19         size = options['size']
20         bleed = 20 if options['bleed'] else 0
21         wldoc = Book.objects.get(slug=slug).wldocument()
22         cover = make_cover(wldoc.book_info, width=size, bleed=bleed)
23         cover.save('%s.jpg' % slug)