2 # -*- coding: utf-8 -*-
4 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
5 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
8 __date__ ="$2009-09-08 14:31:26$"
9 from django.core.management.base import NoArgsCommand
10 from toolbar.models import Button, ButtonGroup
11 from django.utils import simplejson as json
14 class Command(NoArgsCommand):
16 def handle_noargs(self, **options):
17 buttons = Button.objects.all()
18 print "Validating parameters... "
22 v = json.loads(b.params)
24 print 'Trying to fix button "%s" ...' % b.slug
27 if params[-1] == u')':
30 v = son.loads(re.sub(u'([\\w-]+)\\s*:', u'"\\1": ', params).encode('utf-8'))
32 print "Unable to fix '%s' " % b.params
33 print "Try to fix this button manually and rerun the script."
37 b.params = json.dumps(v)
40 print "Merge duplicate buttons (if any)..."
43 if b.slug not in hash:
48 print "Found duplicate of '%s'" % b.slug
51 remove_duplicate = True
52 if a.params != b.params:
53 print "Conflicting params for duplicate of '%s'." % b.slug
54 print "Groups will be joined, but won't remove duplicates."
55 remove_duplicate = False
57 for g in b.group.all():
66 print "Searching for empty groups and orphaned buttons:"
67 for g in ButtonGroup.objects.all():
68 if len(g.button_set.all()) == 0:
69 print "Empty group: '%s'" % g.slug
71 for b in Button.objects.all():
72 if len(b.group.all()) == 0:
73 print "orphan: '%s'" % b.slug