mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
Allow backup_value to be specified to the 'getkey' report helper (#8719)
This commit is contained in:
parent
17fd7f32a4
commit
53792693f5
@ -103,7 +103,7 @@ def getindex(container: list, index: int) -> Any:
|
|||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def getkey(container: dict, key: str) -> Any:
|
def getkey(container: dict, key: str, backup_value: Optional[any] = None) -> Any:
|
||||||
"""Perform key lookup in the provided dict object.
|
"""Perform key lookup in the provided dict object.
|
||||||
|
|
||||||
This function is provided to get around template rendering limitations.
|
This function is provided to get around template rendering limitations.
|
||||||
@ -112,14 +112,13 @@ def getkey(container: dict, key: str) -> Any:
|
|||||||
Arguments:
|
Arguments:
|
||||||
container: A python dict object
|
container: A python dict object
|
||||||
key: The 'key' to be found within the dict
|
key: The 'key' to be found within the dict
|
||||||
|
backup_value: A backup value to return if the key is not found
|
||||||
"""
|
"""
|
||||||
if type(container) is not dict:
|
if type(container) is not dict:
|
||||||
logger.warning('getkey() called with non-dict object')
|
logger.warning('getkey() called with non-dict object')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if key in container:
|
return container.get(key, backup_value)
|
||||||
return container[key]
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user