def get_field_value_from_context(field_name, context_list):
field_path = field_name.split('<STR_LIT:.>')<EOL>if field_path[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>context_index = <NUM_LIT:0><EOL>field_path.pop(<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>context_index = -<NUM_LIT:1><EOL>while field_path[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>context_index -= <NUM_LIT:1><EOL>field_path.pop(<NUM_LIT:0>)<EOL><DEDENT><DEDENT>try:<EOL><INDENT>field_value = context_list[context_index]<EOL>while len(field_path):<EOL><INDENT>field = field_path.pop(<NUM_LIT:0>)<EOL>if isinstance(field_value, (list, tuple, ListModel)):<EOL><INDENT>if field.isdigit():<EOL><INDENT>field = int(field)<EOL><DEDENT>field_value = field_value[field]<EOL><DEDENT>elif isinstance(field_value, dict):<EOL><INDENT>try:<EOL><INDENT>field_value = field_value[field]<EOL><DEDENT>except KeyError:<EOL><INDENT>if field.isdigit():<EOL><INDENT>field = int(field)<EOL>field_value = field_value[field]<EOL><DEDENT>else:<EOL><INDENT>field_value = None<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>field_value = getattr(field_value, field)<EOL><DEDENT><DEDENT>return field_value<EOL><DEDENT>except (IndexError, AttributeError, KeyError, TypeError):<EOL><INDENT>return None<EOL><DEDENT>
Helper to get field value from string path.
String '<context>' is used to go up on context stack. It just
can be used at the beginning of path: <context>.<context>.field_name_1
On the other hand, '<root>' is used to start lookup from first item on context.