1 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.core.management.base import NoArgsCommand
6 from toolbar.models import Button, ButtonGroup
11 class Command(NoArgsCommand):
13 def handle_noargs(self, **options):
14 buttons = Button.objects.all()
15 print("Validating parameters... ")
19 v = json.loads(b.params)
20 except ValueError as e:
21 print('Trying to fix button "%s" ...' % b.slug)
24 if params[-1] == u')':
27 v = son.loads(re.sub(u'([\\w-]+)\\s*:', u'"\\1": ', params).encode('utf-8'))
28 except ValueError as e:
29 print("Unable to fix '%s' " % b.params)
30 print("Try to fix this button manually and rerun the script.")
34 b.params = json.dumps(v)
37 print("Merge duplicate buttons (if any)...")
40 if b.slug not in hash:
45 print("Found duplicate of '%s'" % b.slug)
48 remove_duplicate = True
49 if a.params != b.params:
50 print("Conflicting params for duplicate of '%s'." % b.slug)
51 print("Groups will be joined, but won't remove duplicates.")
52 remove_duplicate = False
54 for g in b.group.all():
63 print("Searching for empty groups and orphaned buttons:")
64 for g in ButtonGroup.objects.all():
65 if len(g.button_set.all()) == 0:
66 print("Empty group: '%s'" % g.slug)
68 for b in Button.objects.all():
69 if len(b.group.all()) == 0:
70 print("orphan: '%s'" % b.slug)