1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
7 from django.core.management.base import BaseCommand
10 def query_yes_no(question, default="yes"):
11 """Ask a yes/no question via raw_input() and return their answer.
13 "question" is a string that is presented to the user.
14 "default" is the presumed answer if the user just hits <Enter>.
15 It must be "yes" (the default), "no" or None (meaning
16 an answer is required of the user).
18 The "answer" return value is one of "yes" or "no".
20 valid = {"yes": True, "y": True, "ye": True,
21 "no": False, "n": False}
24 elif default == "yes":
29 raise ValueError("invalid default answer: '%s'" % default)
32 sys.stdout.write(question + prompt)
33 choice = raw_input().lower()
34 if default is not None and choice == '':
39 sys.stdout.write("Please respond with 'yes' or 'no' (or 'y' or 'n').\n")
42 class Command(BaseCommand):
43 help = 'Reindex pictures.'
45 def add_arguments(self, parser):
47 '-n', '--picture-id', action='store_true', dest='picture_id',
48 default=False, help='picture id instead of slugs')
49 self.add_argument('slug/id', nargs='*', metavar='slug/id')
51 def handle(self, **opts):
52 from picture.models import Picture
53 from search.index import Index
58 for a in opts['args']:
59 if opts['picture_id']:
60 pictures += Picture.objects.filter(id=int(a)).all()
62 pictures += Picture.objects.filter(slug=a).all()
64 pictures = list(Picture.objects.order_by('slug'))
75 # we might not be able to rollback
79 retry = query_yes_no("Retry?")