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
21 tag_with_name = r"<([^>]+)name=\"([^>]+)>"
23 def fix(book, author, dry_run=True):
25 print "%s ==> does not contain chunks" % book.slug
28 txt = fc.materialize()
30 newtxt, cnt = re.subn(tag_with_name, r'<\1nazwa="\2>', txt)
32 print "%s ==> nothing changed" % book.slug
36 print "%s ==> changing" % book.slug
37 fc.commit(newtxt, author=author, description=u"Automatyczna zmiana atrybutu name na nazwa")
39 print "%s ==> i would change this" % book.slug
44 from django.contrib.auth.models import User
45 opts, oth_ = getopt.getopt(sys.argv[1:],
48 dry_run = not (("--seriously",'') in opts)
49 me = User.objects.get(username='marcinkoziej')
51 print "This is a dry run, to really fix something, run with --seriously"
52 for b in Book.objects.all():