From 95079a003bfba48fcdd4d43e3bc571d79a2d2b17 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 10 Jan 2020 08:19:33 +0100 Subject: [PATCH 1/2] =?UTF-8?q?nanterre:=20pr=C3=A9vient=20les=20erreurs?= =?UTF-8?q?=20unicode=20quand=20on=20pipe=20rsu-duplicates=20(#37038)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/commands/rsu-duplicates.py | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/zoo/zoo_nanterre/management/commands/rsu-duplicates.py b/zoo/zoo_nanterre/management/commands/rsu-duplicates.py index f632e08..f6b75eb 100644 --- a/zoo/zoo_nanterre/management/commands/rsu-duplicates.py +++ b/zoo/zoo_nanterre/management/commands/rsu-duplicates.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from __future__ import unicode_literals + import sys from decimal import Decimal import datetime @@ -101,14 +103,14 @@ class Command(BaseCommand): for t in find_duplicates(count=count, limit=limit, days=days, ids=ids, progression=True): if verbosity > 1: - print >>sys.stdout, ( + self.stdout.write( 'New duplicates / persons scanned / persons total :' - ' %05d / %05d / %05d\r' % t), - sys.stdout.flush() + ' %05d / %05d / %05d\r' % t) + self.stdout.flush() if verbosity > 1: print if verbosity > 0 and t[0]: - print 'Found %d new duplicates.' % t[0] + self.stdout.write('Found %d new duplicates.' % t[0]) elif command == 'delete': qs = Duplicate.objects.all() if limit: @@ -120,7 +122,7 @@ class Command(BaseCommand): qs = qs[:count] if days: since = now() - datetime.timedelta(days=days) - print 'Duplicates created after', since + self.stdout.write('Duplicates created after', since) qs = qs.filter(created__gte=since) if false: qs = qs.filter(state=Duplicate.STATE_FALSE_POSITIVE) @@ -133,6 +135,8 @@ class Command(BaseCommand): column_size = max(column_size, len(individu_caption(duplicate.first)), len(individu_caption(duplicate.second))) + self.stdout.write('%d duplicates\n' % qs.count()) + if false: table = Table(['Declared false', 'ID', 'Name', 'ID', 'Name', 'Score']) table.add_rows([(d.modified.isoformat(), d.first_id, individu_caption(d.first), @@ -142,7 +146,7 @@ class Command(BaseCommand): table.add_rows([(d.modified.isoformat(), d.first_id, individu_caption(d.first), d.second_id, individu_caption(d.second), d.content['dedup_choice'], d.score) for d in qs]) - print u'| %6s | %*s | %6s | %*s | %5s |' % ( + self.stdout.write('| %6s | %*s | %6s | %*s | %5s |' % ( 'ID', column_size, u'État civil', @@ -150,9 +154,9 @@ class Command(BaseCommand): column_size, u'État civil', 'Score', - ) + )) for duplicate in qs: - print '| %6d | %*s | %6d | %*s | %3d %% |' % ( + self.stdout.write('| %6d | %*s | %6d | %*s | %3d %% |' % ( duplicate.first_id, column_size, individu_caption(duplicate.first), @@ -160,4 +164,4 @@ class Command(BaseCommand): column_size, individu_caption(duplicate.second), duplicate.score * Decimal(100), - ) + )) -- 2.24.0