2 # -*- conding: utf-8 -*-
4 __date__ ="$2009-09-08 14:31:26$"
5 from django.core.management.base import NoArgsCommand
6 from toolbar.models import Button, ButtonGroup
7 from django.utils import simplejson as json
10 class Command(NoArgsCommand):
12 def handle_noargs(self, **options):
13 buttons = Button.objects.all()
14 print "Validating parameters... "
18 v = json.loads(b.params)
20 print 'Trying to fix button "%s" ...' % b.slug
23 if params[-1] == u')':
26 v = son.loads(re.sub(u'([\\w-]+)\\s*:', u'"\\1": ', params).encode('utf-8'))
28 print "Unable to fix '%s' " % b.params
29 print "Try to fix this button manually and rerun the script."
33 b.params = json.dumps(v)
36 print "Merge duplicate buttons (if any)..."
39 if b.slug not in hash:
44 print "Found duplicate of '%s'" % b.slug
47 remove_duplicate = True
48 if a.params != b.params:
49 print "Conflicting params for duplicate of '%s'." % b.slug
50 print "Groups will be joined, but won't remove duplicates."
51 remove_duplicate = False
53 for g in b.group.all():
62 print "Searching for empty groups and orphaned buttons:"
63 for g in ButtonGroup.objects.all():
64 if len(g.button_set.all()) == 0:
65 print "Empty group: '%s'" % g.slug
67 for b in Button.objects.all():
68 if len(b.group.all()) == 0:
69 print "orphan: '%s'" % b.slug