Index: filters/find.py |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/filters/find.py |
@@ -0,0 +1,8 @@ |
+from jinja2 import environmentfilter, Environment |
Wladimir Palant
2015/03/22 22:06:42
Nit: Environment isn't used. Not that it really ma
|
+ |
+@environmentfilter |
+def find(environment, sequence, value, attr=None): |
Wladimir Palant
2015/03/22 22:06:42
Please keep attribute as the parameter name here,
saroyanm
2015/03/22 23:40:51
Done.
|
+ for item in sequence: |
+ if (item if attr is None else environment.getitem(item, attr)) == value: |
+ return item |
+ return None |