"[EPIC] Report option on everything - reports models

This commit is contained in:
Eliot Berriot 2019-08-22 11:30:30 +02:00
parent 079671ef7a
commit a6cf2ce019
22 changed files with 792 additions and 21 deletions

View file

@ -154,7 +154,7 @@ def order_for_search(qs, field):
def recursive_getattr(obj, key, permissive=False):
"""
Given a dictionary such as {'user': {'name': 'Bob'}} and
Given a dictionary such as {'user': {'name': 'Bob'}} or and object and
a dotted string such as user.name, returns 'Bob'.
If the value is not present, returns None
@ -162,7 +162,10 @@ def recursive_getattr(obj, key, permissive=False):
v = obj
for k in key.split("."):
try:
v = v.get(k)
if hasattr(v, "get"):
v = v.get(k)
else:
v = getattr(v, k)
except (TypeError, AttributeError):
if not permissive:
raise