@register.simple_tag<EOL>def get_item_by_key(passed_list, key, value):
if value in [None, '<STR_LIT>']:<EOL><INDENT>return<EOL><DEDENT>if type(passed_list) in [QuerySet, PolymorphicQuerySet]:<EOL><INDENT>sub_list = passed_list.filter(**{key: value})<EOL><DEDENT>else:<EOL><INDENT>sub_list = [x for x in passed_list if x.get(key) == value]<EOL><DEDENT>if len(sub_list) == <NUM_LIT:1>:<EOL><INDENT>return sub_list[<NUM_LIT:0>]<EOL><DEDENT>return sub_list<EOL>
This one allows us to get one or more items from a list of
dictionaries based on the value of a specified key, where
both the key and the value can be variable names.  Does
not work with None or null string passed values.