1 # -*- coding: utf-8 -*-
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.
7 from django.contrib.auth.models import User
8 from django.core.management.base import BaseCommand
9 from catalogue.models import Book
12 class XmlUpdaterCommand(BaseCommand):
13 """Base class for creating massive XML-updating commands.
15 In a subclass, provide an XmlUpdater class in the `updater' attribute.
19 def add_arguments(self, parser):
21 '-q', '--quiet', action='store_false', dest='verbose',
22 default=True, help='Less output')
24 '-d', '--dry-run', action='store_true', dest='dry_run',
25 default=False, help="Don't actually touch anything")
27 '-u', '--username', dest='username', metavar='USER',
28 help='Assign commits to this user (required, preferably yourself).')
30 def handle(self, *args, **options):
31 verbose = options.get('verbose')
32 dry_run = options.get('dry_run')
33 username = options.get('username')
36 user = User.objects.get(username=username)
38 print('Please provide a username.')
41 books = Book.objects.filter(slug__in=args) if args else None
43 updater = self.updater()
44 updater.run(user, verbose=verbose, dry_run=dry_run, books=books)
45 updater.print_results()