Add audience and thema data to catalogue. Also: nicer cover view.
[redakcja.git] / src / documents / management / commands / mark_final.py
1 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 import sys
5 from django.contrib.auth.models import User
6 from django.core.management import BaseCommand
7
8 from documents.models import Book, Chunk
9
10
11 class Command(BaseCommand):
12     args = 'slug_file'
13
14     def add_arguments(self, parser):
15         self.add_argument(
16             '-u', '--username', dest='username', metavar='USER',
17             help='Assign commits to this user (required).')
18
19     def handle(self, slug_file, **options):
20         username = options.get('username')
21
22         if username:
23             user = User.objects.get(username=username)
24         else:
25             print('Please provide a username.')
26             sys.exit(1)
27
28         slugs = [line.strip() for line in open(slug_file)]
29         books = Book.objects.filter(slug__in=slugs)
30
31         for book in books:
32             print('processing %s' % book.slug)
33             for chunk in book.chunk_set.all():
34                 src = chunk.head.materialize()
35                 chunk.commit(
36                     text=src,
37                     author=user,
38                     description=u'Ostateczna akceptacja merytoryczna przez kierownika literackiego.',
39                     tags=[Chunk.tag_model.objects.get(slug='editor-proofreading')],
40                     publishable=True
41                 )
42             print('committed %s' % book.slug)