Skip to content
Snippets Groups Projects
Verified Commit d86305e8 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Make get_dict do the full access discovery like the normal access operator.

parent 5997f19d
No related branches found
No related tags found
No related merge requests found
......@@ -6,5 +6,14 @@ register = template.Library()
@register.filter
def get_dict(value: Dict[Any, Any], arg: Any) -> Any:
return value.get(arg, None)
def get_dict(value: Any, arg: Any) -> Any:
"""Gets an attribute of an object dynamically from a string name"""
if hasattr(value, str(arg)):
return getattr(value, arg)
elif hasattr(value, 'has_key') and value.has_key(arg):
return value[arg]
elif str(arg).isnumeric() and len(value) > int(arg):
return value[int(arg)]
else:
return None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment