From a39c137ac4c7538e906ff9e0233cfa8677c19905 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Mon, 16 Mar 2015 15:16:47 +0000 Subject: [PATCH] Fixed output of fixtree on Python 2/MySQL MySQL returns longs which end up in the output of fixtree as [1L, 2L, ...]. This commit makes sure that longs are always output without the 'L' suffix --- .../management/commands/fixtree.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/wagtail/wagtailcore/management/commands/fixtree.py b/wagtail/wagtailcore/management/commands/fixtree.py index 67651e479..a85c21a47 100644 --- a/wagtail/wagtailcore/management/commands/fixtree.py +++ b/wagtail/wagtailcore/management/commands/fixtree.py @@ -20,6 +20,11 @@ class Command(BaseCommand): ) option_list = BaseCommand.option_list + base_options + def numberlist_to_string(self, numberlist): + # Converts a list of numbers into a string + # Doesn't put "L" after longs + return '[' + ', '.join(map(str, numberlist)) + ']' + def handle(self, **options): any_problems_fixed = False @@ -34,9 +39,9 @@ class Command(BaseCommand): (bad_alpha, bad_path, orphans, bad_depth, bad_numchild) = Page.find_problems() if bad_depth: - self.stdout.write("Incorrect depth value found for pages: %r" % bad_depth) + self.stdout.write("Incorrect depth value found for pages: %s" % self.numberlist_to_string(bad_depth)) if bad_numchild: - self.stdout.write("Incorrect numchild value found for pages: %r" % bad_numchild) + self.stdout.write("Incorrect numchild value found for pages: %s" % self.numberlist_to_string(bad_numchild)) if bad_depth or bad_numchild: Page.fix_tree(destructive=False) @@ -89,15 +94,15 @@ class Command(BaseCommand): if any((bad_alpha, bad_path, orphans, bad_depth, bad_numchild)): self.stdout.write("Remaining problems (cannot fix automatically):") if bad_alpha: - self.stdout.write("Invalid characters found in path for pages: %r" % bad_alpha) + self.stdout.write("Invalid characters found in path for pages: %s" % self.numberlist_to_string(bad_alpha)) if bad_path: - self.stdout.write("Invalid path length found for pages: %r" % bad_path) + self.stdout.write("Invalid path length found for pages: %s" % self.numberlist_to_string(bad_path)) if orphans: - self.stdout.write("Orphaned pages found: %r" % orphans) + self.stdout.write("Orphaned pages found: %s" % self.numberlist_to_string(orphans)) if bad_depth: - self.stdout.write("Incorrect depth value found for pages: %r" % bad_depth) + self.stdout.write("Incorrect depth value found for pages: %s" % self.numberlist_to_string(bad_depth)) if bad_numchild: - self.stdout.write("Incorrect numchild value found for pages: %r" % bad_numchild) + self.stdout.write("Incorrect numchild value found for pages: %s" % self.numberlist_to_string(bad_numchild)) elif any_problems_fixed: self.stdout.write("All problems fixed.")