Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: filters/find.py

Issue 5994668214976512: Issue 662 - Job links shouldn't use anchors (Closed)
Patch Set: Created March 22, 2015, 11:44 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | includes/jobs/footer.tmpl » ('j') | pages/jobs/index.tmpl » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: filters/find.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/filters/find.py
@@ -0,0 +1,11 @@
+def getattribute(obj, attribute):
Sebastian Noack 2015/03/23 10:45:21 Why don't you use environment.getitem() anymore?
saroyanm 2015/03/23 10:59:13 I've changed according to the last Reply here: htt
Sebastian Noack 2015/03/23 11:19:59 Sorry, I missed that comment. However, I don't agr
Sebastian Noack 2015/03/23 12:31:14 For reference: 13:15:01 <snoack> mitsuhiko: Is En
saroyanm 2015/03/23 13:07:50 Done.
+ try:
+ return getattr(obj, str(attribute))
+ except AttributeError:
+ return obj[attribute]
+
+def find(sequence, value, attribute=None):
+ for item in sequence:
+ if (item if attribute is None else getattribute(item, attribute)) == value:
+ return item
+ return None
« no previous file with comments | « no previous file | includes/jobs/footer.tmpl » ('j') | pages/jobs/index.tmpl » ('J')

Powered by Google App Engine
This is Rietveld