Meta errors in alerts.
[redakcja.git] / src / toolbar / management / commands / fixbuttons.py
index de48ced..0eb8323 100644 (file)
@@ -1,6 +1,3 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-#
 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
@@ -15,29 +12,29 @@ class Command(NoArgsCommand):
 
     def handle_noargs(self, **options):
         buttons = Button.objects.all()
 
     def handle_noargs(self, **options):
         buttons = Button.objects.all()
-        print "Validating parameters... "
+        print("Validating parameters... ")
         for b in buttons:
             params = b.params
             try:
                 v = json.loads(b.params)
         for b in buttons:
             params = b.params
             try:
                 v = json.loads(b.params)
-            except ValueError, e:
-                print 'Trying to fix button "%s" ...' % b.slug
+            except ValueError as 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'))
                 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."
+                except ValueError as 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()
 
                     return False
 
             # resave
             b.params = json.dumps(v)
             b.save()
 
-        print "Merge duplicate buttons (if any)..."
+        print("Merge duplicate buttons (if any)...")
         hash = {}
         for b in buttons:
             if b.slug not in hash:
         hash = {}
         for b in buttons:
             if b.slug not in hash:
@@ -45,13 +42,13 @@ class Command(NoArgsCommand):
                 continue
 
             # duplicate button
                 continue
 
             # duplicate button
-            print "Found duplicate of '%s'" % b.slug
+            print("Found duplicate of '%s'" % b.slug)
             a = hash[b.slug]
 
             remove_duplicate = True
             if a.params != b.params:
             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."
+                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():
                 remove_duplicate = False
 
             for g in b.group.all():
@@ -63,11 +60,11 @@ class Command(NoArgsCommand):
             if remove_duplicate:
                 b.delete()
 
             if remove_duplicate:
                 b.delete()
 
-        print "Searching for empty groups and orphaned buttons:"
+        print("Searching for empty groups and orphaned buttons:")
         for g in ButtonGroup.objects.all():
             if len(g.button_set.all()) == 0:
         for g in ButtonGroup.objects.all():
             if len(g.button_set.all()) == 0:
-                print "Empty group: '%s'" % g.slug
+                print("Empty group: '%s'" % g.slug)
 
         for b in Button.objects.all():
             if len(b.group.all()) == 0:
 
         for b in Button.objects.all():
             if len(b.group.all()) == 0:
-                print "orphan: '%s'" % b.slug
+                print("orphan: '%s'" % b.slug)