From 8a49e066af3d88d1edb34aa1680b668c959dfcf7 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Mon, 30 May 2016 16:48:11 +0200 Subject: [PATCH] Clarified and extended the docs for the `{select|reject}[attr]` filters. (#231) --- jinja2/filters.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/jinja2/filters.py b/jinja2/filters.py index 9b553a23..a4504069 100644 --- a/jinja2/filters.py +++ b/jinja2/filters.py @@ -846,8 +846,10 @@ def do_map(*args, **kwargs): @contextfilter def do_select(*args, **kwargs): - """Filters a sequence of objects by applying a test to the object and only - selecting the ones with the test succeeding. + """Filters a sequence of objects by applying a test to each object, + and only selecting the objects with the test succeeding. + + If no test is specified, each object will be evaluated as a boolean. Example usage: @@ -863,8 +865,10 @@ def do_select(*args, **kwargs): @contextfilter def do_reject(*args, **kwargs): - """Filters a sequence of objects by applying a test to the object and - rejecting the ones with the test succeeding. + """Filters a sequence of objects by applying a test to each object, + and rejecting the objects with the test succeeding. + + If no test is specified, each object will be evaluated as a boolean. Example usage: @@ -879,8 +883,12 @@ def do_reject(*args, **kwargs): @contextfilter def do_selectattr(*args, **kwargs): - """Filters a sequence of objects by applying a test to an attribute of an - object and only selecting the ones with the test succeeding. + """Filters a sequence of objects by applying a test to the specified + attribute of each object, and only selecting the objects with the + test succeeding. + + If no test is specified, the attribute's value will be evaluated as + a boolean. Example usage: @@ -896,8 +904,12 @@ def do_selectattr(*args, **kwargs): @contextfilter def do_rejectattr(*args, **kwargs): - """Filters a sequence of objects by applying a test to an attribute of an - object or the attribute and rejecting the ones with the test succeeding. + """Filters a sequence of objects by applying a test to the specified + attribute of each object, and rejecting the objects with the test + succeeding. + + If no test is specified, the attribute's value will be evaluated as + a boolean. .. sourcecode:: jinja -- 2.47.3