Simplify settings loading a bit. Remove the things which haven't been working for...
[redakcja.git] / src / catalogue / management / commands / mark_final.py
1 # -*- coding: utf-8 -*-
2 #
3 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 #
6 import sys
7 from django.contrib.auth.models import User
8 from optparse import make_option
9
10 from django.core.management import BaseCommand
11
12 from catalogue.models import Book, Chunk
13
14
15 class Command(BaseCommand):
16     option_list = BaseCommand.option_list + (
17         # make_option('-q', '--quiet', action='store_false', dest='verbose',
18         #     default=True, help='Less output'),
19         # make_option('-d', '--dry-run', action='store_true', dest='dry_run',
20         #     default=False, help="Don't actually touch anything"),
21         make_option(
22             '-u', '--username', dest='username', metavar='USER',
23             help='Assign commits to this user (required).'),
24     )
25     args = 'slug_file'
26
27     def handle(self, slug_file, **options):
28         username = options.get('username')
29
30         if username:
31             user = User.objects.get(username=username)
32         else:
33             print 'Please provide a username.'
34             sys.exit(1)
35
36         slugs = [line.strip() for line in open(slug_file)]
37         books = Book.objects.filter(slug__in=slugs)
38
39         for book in books:
40             print 'processing %s' % book.slug
41             for chunk in book.chunk_set.all():
42                 src = chunk.head.materialize()
43                 chunk.commit(
44                     text=src,
45                     author=user,
46                     description=u'Ostateczna akceptacja merytoryczna przez kierownika literackiego.',
47                     tags=[Chunk.tag_model.objects.get(slug='editor-proofreading')],
48                     publishable=True
49                 )
50             print 'committed %s' % book.slug