``gt``, ``ge``. (`#665`_)
- ``import`` statement cannot end with a trailing comma. (`#617`_, `#618`_)
- ``indent`` filter will not indent blank lines by default. (`#685`_)
+- Add ``reverse`` argument for ``dictsort`` filter. (`#692`_)
.. _#469: https://github.com/pallets/jinja/pull/469
.. _#475: https://github.com/pallets/jinja/pull/475
.. _#618: https://github.com/pallets/jinja/pull/618
.. _#665: https://github.com/pallets/jinja/pull/665
.. _#685: https://github.com/pallets/jinja/pull/685
+.. _#692: https://github.com/pallets/jinja/pull/692
Version 2.9.6
-------------
)
assert tmpl.render(given='yes') == 'no|False|no|yes'
- def test_dictsort(self, env):
- tmpl = env.from_string(
- '{{ foo|dictsort }}|'
- '{{ foo|dictsort(true) }}|'
- '{{ foo|dictsort(false, "value") }}'
- )
- out = tmpl.render(foo={"aa": 0, "b": 1, "c": 2, "AB": 3})
- assert out == ("[('aa', 0), ('AB', 3), ('b', 1), ('c', 2)]|"
- "[('AB', 3), ('aa', 0), ('b', 1), ('c', 2)]|"
- "[('aa', 0), ('b', 1), ('c', 2), ('AB', 3)]")
+ @pytest.mark.parametrize('args,expect', (
+ ('', "[('aa', 0), ('AB', 3), ('b', 1), ('c', 2)]"),
+ ('true', "[('AB', 3), ('aa', 0), ('b', 1), ('c', 2)]"),
+ ('by="value"', "[('aa', 0), ('b', 1), ('c', 2), ('AB', 3)]"),
+ ('reverse=true', "[('c', 2), ('b', 1), ('AB', 3), ('aa', 0)]")
+ ))
+ def test_dictsort(self, env, args, expect):
+ t = env.from_string('{{{{ foo|dictsort({args}) }}}}'.format(args=args))
+ out = t.render(foo={"aa": 0, "b": 1, "c": 2, "AB": 3})
+ assert out == expect
def test_batch(self, env):
tmpl = env.from_string("{{ foo|batch(3)|list }}|"