@@ -0,0 +1,1847 @@
+# -*- coding: utf-8 -*-%0A#%0A# This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.%0A# Copyright %C2%A9 Fundacja Nowoczesna Polska. See NOTICE for more information.%0A#%0Aimport sys%0Afrom django.contrib.auth.models import User%0Afrom optparse import make_option%0A%0Afrom collections import defaultdict%0Afrom django.core.management import BaseCommand%0A%0Afrom catalogue.models import Book, Chunk%0A%0A%0Aclass Command(BaseCommand):%0A    option_list = BaseCommand.option_list + (%0A        # make_option('-q', '--quiet', action='store_false', dest='verbose',%0A        #     default=True, help='Less output'),%0A        # make_option('-d', '--dry-run', action='store_true', dest='dry_run',%0A        #     default=False, help=%22Don't actually touch anything%22),%0A        make_option(%0A            '-u', '--username', dest='username', metavar='USER',%0A            help='Assign commits to this user (required).'),%0A    )%0A    args = 'slug_file'%0A%0A    def handle(self, slug_file, **options):%0A        username = options.get('username')%0A%0A        if username:%0A            user = User.objects.get(username=username)%0A        else:%0A            print 'Please provide a username.'%0A            sys.exit(1)%0A%0A        slugs = %5Bline.strip() for line in open(slug_file)%5D%0A        books = Book.objects.filter(slug__in=slugs)%0A%0A        for book in books:%0A            print 'processing %25s' %25 book.slug%0A            chunk = book.chunk_set.first()%0A            src = chunk.head.materialize()%0A            new_head = chunk.commit(%0A                text=src,%0A                author=user,%0A                description=u'Ostateczna akceptacja merytoryczna przez kierownika literackiego.',%0A                tags=%5BChunk.tag_model.objects.get(slug='editor-proofreading')%5D,%0A                publishable=True%0A            )%0A            print 'committed %25s' %25 book.slug%0A            new_head.set_publishable(True)%0A

add command to mark documents in bulk