From 7448037c65b9001af3f935954f14a7610c95fb71 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Wed, 26 Feb 2020 21:28:51 +0000 Subject: [PATCH] Tweaked the show_messages managment command output. - Legacy-Id: 17352 --- ietf/message/management/commands/show_messages.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ietf/message/management/commands/show_messages.py b/ietf/message/management/commands/show_messages.py index c97bb96e5..ceea5c21c 100644 --- a/ietf/message/management/commands/show_messages.py +++ b/ietf/message/management/commands/show_messages.py @@ -11,6 +11,7 @@ from django.core.management.base import BaseCommand import debug # pyflakes:ignore from ietf.message.models import Message +from ietf.utils.mail import parseaddr class Command(BaseCommand): help = 'Show messages, by default unsent messages' @@ -55,16 +56,20 @@ class Command(BaseCommand): messages = messages.filter(time__gte=options['start']) if options['stop']: messages = messages.filter(sent__lte=options['stop']) - self.stdout.write("\nShowimg %s messages between %s and %s:\n\n" % (options['state'], options['start'], options['stop'])) + selection_str = "%s messages between %s and %s" % (options['state'], options['start'], options['stop']) + else: - self.stdout.write("\nShowimg %s messages since %s:\n\n" % (options['state'], options['start'])) + selection_str = "%s messages since %s" % (options['state'], options['start']) + self.stdout.write("\nShowimg %s:\n\n" % selection_str) if options['pk']: self.stdout.write(','.join([ str(pk) for pk in messages.values_list('pk', flat=True)] )) else: for m in messages: + def addr(f): + return parseaddr(f)[1] to = ','.join( a[1] for a in email.utils.getaddresses([m.to]) ) - self.stdout.write('%s %16s %16s %72s %s -> %s "%s"\n' % + self.stdout.write('%s %16s %16s %56s %s -> %s "%s"\n' % (m.pk, m.time.strftime('%Y-%m-%d %H:%M'), m.sent and m.sent.strftime('%Y-%m-%d %H:%M') or '', - m.msgid.strip('<>'), m.frm, to, m.subject.strip())) - \ No newline at end of file + m.msgid.strip('<>'), addr(m.frm), to, m.subject.strip())) + self.stdout.write("\n%s messages (%s)\n" % (messages.count(), selection_str))