2 # -*- coding: utf-8 -*-
3 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
8 sys.path.append('./apps')
9 sys.path.append('./lib')
11 from django.core.management import setup_environ
12 from redakcja import settings
14 setup_environ(settings)
16 from catalogue.models import Book, Chunk
19 from django.db import transaction
21 if len(sys.argv) != 4:
22 print "dump-book slug-part chunk-no to-position"
26 chunk_idx = int(sys.argv[2])
27 new_position = int(sys.argv[3])
29 with transaction.commit_on_success():
30 books = Book.objects.filter(slug__contains=term)
32 for b in range(len(books)):
33 print "%d) %s" % (b+1, books[b].slug)
40 chunks_total = len(book)
41 max_number = max(c.number for c in book)
42 moving_chunk = next(c for c in book if c.number == chunk_idx)
44 moving_chunk.number = max_number+2
48 for i in range(chunks_total-1, -1, -1):
50 chunk.number = i + 1 + adjust
52 if i + 1 == new_position:
56 moving_chunk.number = new_position
59 book = Book.objects.get(pk=book.pk)
63 print "is this ok (y/n)? "
68 raise Exception("Aborting")