From bea94cb9538a55b1376afd42c2ce751efce62cfe Mon Sep 17 00:00:00 2001 From: Mark Sapiro Date: Wed, 26 Jul 2017 08:11:33 -0700 Subject: Ensure all holds/rejects have a reason. --- src/mailman/chains/base.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/mailman/chains/base.py') diff --git a/src/mailman/chains/base.py b/src/mailman/chains/base.py index 59125ba69..9507d8fbc 100644 --- a/src/mailman/chains/base.py +++ b/src/mailman/chains/base.py @@ -18,6 +18,7 @@ """Base class for terminal chains.""" from mailman.config import config +from mailman.core.i18n import _ from mailman.interfaces.chain import ( IChain, IChainIterator, IChainLink, IMutableChain, LinkAction) from mailman.interfaces.rules import IRule @@ -26,6 +27,24 @@ from public import public from zope.interface import implementer +@public +def format_reasons(reasons): + """Translate and format hold and rejection reasons. + + :param reasons: A list of reasons from the rules that hit. Each reason is + a string to be translated or a tuple consisting of a string with {} + replacements and one or more replacement values. + :returns: A list of the translated and formatted strings. + """ + new_reasons = [] + for reason in reasons: + if isinstance(reason, tuple): + new_reasons.append(_(reason[0]).format(*reason[1:])) + else: + new_reasons.append(_(reason)) + return new_reasons + + @public @implementer(IChainLink) class Link: -- cgit v1.2.3-70-g09d2