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 optparse import make_option
8 from django.contrib.auth.models import User
9 from django.core.management.base import BaseCommand
10 from catalogue.models import Book
13 class XmlUpdaterCommand(BaseCommand):
14 """Base class for creating massive XML-updating commands.
16 In a subclass, provide an XmlUpdater class in the `updater' attribute.
18 option_list = BaseCommand.option_list + (
20 '-q', '--quiet', action='store_false', dest='verbose',
21 default=True, help='Less output'),
23 '-d', '--dry-run', action='store_true', dest='dry_run',
24 default=False, help="Don't actually touch anything"),
26 '-u', '--username', dest='username', metavar='USER',
27 help='Assign commits to this user (required, preferably yourself).'),
31 updater = NotImplemented
33 def handle(self, *args, **options):
34 verbose = options.get('verbose')
35 dry_run = options.get('dry_run')
36 username = options.get('username')
39 user = User.objects.get(username=username)
41 print 'Please provide a username.'
44 books = Book.objects.filter(slug__in=args) if args else None
46 updater = self.updater()
47 updater.run(user, verbose=verbose, dry_run=dry_run, books=books)
48 updater.print_results()