mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Add deep_getattr
This commit is contained in:
parent
97b96f220f
commit
227c960653
1 changed files with 19 additions and 2 deletions
|
@ -18,8 +18,17 @@ def parse_bool(str):
|
|||
raise ValueError(f'Can not parse a bool from "{str}"')
|
||||
|
||||
|
||||
def deep_getattr(object, composed_name):
|
||||
names = composed_name.split(".")
|
||||
attr = getattr(object, names[0])
|
||||
for name in names[1:]:
|
||||
attr = getattr(attr, name)
|
||||
|
||||
return attr
|
||||
|
||||
|
||||
def missing_formatter(view, context, model, name):
|
||||
attr = getattr(model, name)
|
||||
attr = deep_getattr(model, name)
|
||||
if attr is None:
|
||||
return Markup("<span style='color:red'>MISSING</span>")
|
||||
|
||||
|
@ -27,8 +36,16 @@ def missing_formatter(view, context, model, name):
|
|||
|
||||
|
||||
def str_without_semester_formatter(view, context, model, name):
|
||||
attr = getattr(model, name)
|
||||
attr = deep_getattr(model, name)
|
||||
if attr is not None:
|
||||
return attr.str_without_semester()
|
||||
|
||||
return attr
|
||||
|
||||
|
||||
def str_formatter(view, context, model, name):
|
||||
attr = deep_getattr(model, name)
|
||||
if attr is not None:
|
||||
return attr.str()
|
||||
|
||||
return attr
|
||||
|
|
Loading…
Reference in a new issue