LEFT | RIGHT |
1 def getattribute(obj, attribute): | 1 from jinja2 import environmentfilter |
2 try: | |
3 return getattr(obj, str(attribute)) | |
4 except AttributeError: | |
5 return obj[attribute] | |
6 | 2 |
7 def find(sequence, value, attribute=None): | 3 @environmentfilter |
| 4 def find(environment, sequence, value, attribute=None): |
8 for item in sequence: | 5 for item in sequence: |
9 if (item if attribute is None else getattribute(item, attribute)) == value: | 6 if (item if attribute is None else environment.getitem(item, attribute)) ==
value: |
10 return item | 7 return item |
11 return None | 8 return None |
LEFT | RIGHT |