Skip to content

Commit 7dc2300

Browse files
Added the comments for the logic as per the suggetion[CMP-2659]
1 parent a14a536 commit 7dc2300

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

onefuse/admin.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ def get_create_properties(self, template_properties: dict):
740740
"""
741741
Parse a dict to find any properties prepended with
742742
OneFuse_CreateProperties_. If found, extract the key:value out of the
743-
property and return them as a dict.
743+
property and return them as a dict. Supports both single objects and arrays of objects.
744744
745745
Ex:
746746
{
@@ -769,21 +769,28 @@ def get_create_properties(self, template_properties: dict):
769769
create_properties = {}
770770
pattern = re.compile('OneFuse_CreateProperties_')
771771
for key in template_properties.keys():
772+
# Match the key against a defined pattern
772773
result = pattern.match(key)
773774
if result is not None:
774775
self.logger.debug(f'Starting parse of key: {key}, '
775776
f'value: {template_properties[key]}')
776777
value_obj = template_properties[key]
777778
self.logger.debug(f'Create Props Object: {value_obj}')
778779

780+
# If the value_obj is a string, parse JSON.
779781
if isinstance(value_obj, str):
780782
value_obj = json.loads(value_obj)
781783

784+
# If the value_obj is a list (array of key/value pairs).
782785
if isinstance(value_obj, list):
783786
for item in value_obj:
787+
# If the item is a dictionary containing both 'key' and 'value'
784788
if isinstance(item, dict) and "key" in item and "value" in item:
789+
# Add the 'key' and 'value' from the item to the create_properties dictionary
785790
create_properties[item["key"]] = item["value"]
791+
# If the value_obj is a single key/value pair containing both 'key' and 'value'
786792
elif isinstance(value_obj, dict) and "key" in value_obj and "value" in value_obj:
793+
# Add the 'key' and 'value' from the dictionary to the create_properties dictionary
787794
create_properties[value_obj["key"]] = value_obj["value"]
788795
return create_properties
789796

0 commit comments

Comments
 (0)