diff --git a/trac/util/presentation.py b/trac/util/presentation.py index 196a6c2b00..c438130977 100644 --- a/trac/util/presentation.py +++ b/trac/util/presentation.py @@ -50,7 +50,7 @@ def jinja2_update(jenv): groupattr=groupattr_filter, htmlattr=htmlattr_filter, max=max_filter, - mix=min_filter, + min=min_filter, trim=trim_filter, ) jenv.tests.update( @@ -138,15 +138,11 @@ def htmlattr_filter(_eval_ctx, d, autospace=True): def max_filter(seq, default=None): """Returns the max value from the sequence.""" - if len(seq): - return max(seq) - return default + return max(seq, default=default) def min_filter(seq, default=None): """Returns the min value from the sequence.""" - if len(seq): - return min(seq) - return default + return min(seq, default=default) def trim_filter(value, what=None): diff --git a/trac/web/tests/chrome.py b/trac/web/tests/chrome.py index 4c43092b9c..82eeb676c0 100644 --- a/trac/web/tests/chrome.py +++ b/trac/web/tests/chrome.py @@ -1269,6 +1269,23 @@ def test(domain=None): test(domain=None) test(domain='messages') + def test_filters_max_min(self): + template = textwrap.dedent("""\ + ${names|map('capitalize')|max(default='(max)')} + ${names|map('capitalize')|min(default='(min)')} + ${names|reject('string')|max(default='(max)')} + ${names|reject('string')|min(default='(min)')} + """) + filename = 'ticket13773.html' + create_file(os.path.join(self.env.templates_dir, filename), template) + + req = MockRequest(self.env) + data = {'names': ['alpha', 'beta', 'gamma']} + content = self.chrome.render_template(req, filename, data, + {'iterable': False}) + self.assertEqual(['Gamma', 'Alpha', '(max)', '(min)'], + str(content, 'utf-8').splitlines()) + def test_suite(): suite = unittest.TestSuite()