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.
5 from django.contrib.auth.models import User
6 from django.core.management.base import BaseCommand
7 from documents.models import Book
10 class XmlUpdaterCommand(BaseCommand):
11 """Base class for creating massive XML-updating commands.
13 In a subclass, provide an XmlUpdater class in the `updater' attribute.
17 def add_arguments(self, parser):
19 '-q', '--quiet', action='store_false', dest='verbose',
20 default=True, help='Less output')
22 '-d', '--dry-run', action='store_true', dest='dry_run',
23 default=False, help="Don't actually touch anything")
25 '-u', '--username', dest='username', metavar='USER',
26 help='Assign commits to this user (required, preferably yourself).')
28 def handle(self, *args, **options):
29 verbose = options.get('verbose')
30 dry_run = options.get('dry_run')
31 username = options.get('username')
34 user = User.objects.get(username=username)
36 print('Please provide a username.')
39 books = Book.objects.filter(slug__in=args) if args else None
41 updater = self.updater()
42 updater.run(user, verbose=verbose, dry_run=dry_run, books=books)
43 updater.print_results()