X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/537012c60af1ea1c0e39949c58df4647ddadc72b..5913c54d19b8f6775633176032161d49f9b2f1aa:/apps/toolbar/management/commands/fixbuttons.py?ds=sidebyside diff --git a/apps/toolbar/management/commands/fixbuttons.py b/apps/toolbar/management/commands/fixbuttons.py deleted file mode 100755 index 627ef25d..00000000 --- a/apps/toolbar/management/commands/fixbuttons.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- conding: utf-8 -__author__="lreqc" -__date__ ="$2009-09-08 14:31:26$" -from django.core.management.base import NoArgsCommand -from toolbar.models import Button -from django.utils import simplejson as json -import re - -class Command(NoArgsCommand): - - def handle_noargs(self, **options): - buttons = Button.objects.all() - print "Validating parameters... " - for b in buttons: - params = b.params; - try: - v = json.loads(b.params) - except ValueError, e: - print 'Trying to fix button "%s" ...' % b.slug - if params[0] == u'(': - params = params[1:] - if params[-1] == u')': - params = params[:-1] - try: - v = son.loads(re.sub(u'([\\w-]+)\\s*:', u'"\\1": ', params).encode('utf-8')) - except ValueError, e: - print "Unable to fix '%s' " % b.params - print "Try to fix this button manually and rerun the script." - return False - - # resave - b.params = json.dumps(v) - b.save() - - print "Merge duplicate buttons (if any)..." - hash = {} - for b in buttons: - if b.slug not in hash: - hash[b.slug] = b - continue - - # duplicate button - print "Found duplicate of '%s'" % b.slug - a = hash[b.slug] - - remove_duplicate = True - if a.params != b.params: - print "Conflicting params for duplicate of '%s'." % b.slug - print "Groups will be joined, but won't remove duplicates." - remove_duplicate = False - - for g in b.group.all(): - a.group.add(g) - - b.group.clear() - - a.save() - b.delete()