File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 3535
3636# return emailMessage
3737
38+ def get_value_from_dict_using_formdata_key (key ,dictionary ):
39+ """
40+ Example:
41+ key="newsletter[newsletter_id]"
42+ dict={"newsletter":{"newsletter_id": 123}}
43+
44+ returns 123
45+ """
46+ #check if we need to go deeper
47+ if '[' in key and ']' in key :
48+ #get top level key e.g. topKey[nextKey][anotherKey] => topKey
49+ topKey = key .split ('[' )[0 ]
50+ #remove top level key, e.g. topKey[nextKey][anotherKey] => nextKey[anotherKey]
51+ topKeyRemoved = key [len (topKey )+ 1 :].replace (']' ,'' ,1 )
52+ #recurse
53+ return get_value_from_dict_using_formdata_key (topKeyRemoved ,dictionary [topKey ])
54+ else :
55+ return dictionary [key ]
56+
3857def in_test_environment ():
3958 """
4059 Returns True if in a test environment, False otherwise.
You can’t perform that action at this time.
0 commit comments