2f15525b662284f79cdcb5fecc69802505bdbf07
[redakcja.git] / apps / toolbar / management / commands / fixbuttons.py
1 # -*- conding: utf-8
2 __author__="lreqc"
3 __date__ ="$2009-09-08 14:31:26$"
4 from django.core.management.base import NoArgsCommand
5 from toolbar.models import Button
6 from django.utils import simplejson as json
7 import re
8
9 class Command(NoArgsCommand):
10     
11     def handle_noargs(self, **options):
12         buttons = Button.objects.all()
13         for b in buttons:
14             params = b.params;
15             try:
16                 v = json.loads(b.params)
17                
18             except ValueError, e:
19                 print 'On button %s: ' % b.label, b.params
20                 print e
21                 # try to fix the bad json
22                 
23                 # cut the parenthis
24                 if params[0] == u'(':
25                     params = params[1:]
26                 if params[-1] == u')':
27                     params = params[:-1]
28
29                 v = json.loads(re.sub(u'([\\w-]+)\\s*:', u'"\\1": ', params).encode('utf-8'))
30             b.params = json.dumps(v)
31             b.save()
32
33
34
35