2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

Allow backup_value to be specified to the 'getkey' report helper (#8719)

This commit is contained in:
Oliver 2024-12-19 09:24:01 +11:00 committed by GitHub
parent 17fd7f32a4
commit 53792693f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -103,7 +103,7 @@ def getindex(container: list, index: int) -> Any:
@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.
This function is provided to get around template rendering limitations.
@ -112,14 +112,13 @@ def getkey(container: dict, key: str) -> Any:
Arguments:
container: A python dict object
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:
logger.warning('getkey() called with non-dict object')
return None
if key in container:
return container[key]
return None
return container.get(key, backup_value)
@register.simple_tag()