From 53792693f5ec35b54d2f72026cc024be0806798e Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 19 Dec 2024 09:24:01 +1100 Subject: [PATCH] Allow backup_value to be specified to the 'getkey' report helper (#8719) --- src/backend/InvenTree/report/templatetags/report.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/backend/InvenTree/report/templatetags/report.py b/src/backend/InvenTree/report/templatetags/report.py index 7093555014..935a47578e 100644 --- a/src/backend/InvenTree/report/templatetags/report.py +++ b/src/backend/InvenTree/report/templatetags/report.py @@ -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()