(form, attachment_name, use_basename=False)
return None
Returns the list of keys used to find attachment_name in the form (None if not found)
    use_basename only applies to values that are an absolute path
Returns the list of keys used to find attachment_name in the form (None if not found)
    use_basename only applies to values that are an absolute path
Returns the list of keys used to find attachment_name in the form ( None if not found ) use_basename only applies to values that are an absolute path
def _find_path_to_question_id(form, attachment_name, use_basename=False):
    """
    Returns the list of keys used to find attachment_name in the form (None if not found)
    use_basename only applies to values that are an absolute path
    """
    if not isinstance(form, dict):
        # Recursive calls should always give `form` a form value.
        # However, https://dimagi-dev.atlassian.net/browse/SAAS-11326
        # was caused by resized repeats, where empty string tokens were
        # inserted rather than no element.
        # This check can be removed when repeats handle resizing.
        return None

    for k, v in form.items():
        if isinstance(v, dict):
            ret = _find_path_to_question_id(v, attachment_name, use_basename=use_basename)
            if ret:
                return [k] + ret
        elif isinstance(v, list):
            for repeat in v:
                ret = _find_path_to_question_id(repeat, attachment_name, use_basename=use_basename)
                if ret:
                    return [k] + ret
        else:
            if use_basename and os.path.isabs(v):
                # only worth using basename if path is absolute since that is the edge case this attempts to solve
                v = os.path.basename(v)
            if v == attachment_name:
                return [k]

    return None
def _find_path_to_question_id ( form , attachment_name , use_basename = False ) : if not isinstance ( form , dict ) : # Recursive calls should always give `form` a form value. # However, https://dimagi-dev.atlassian.net/browse/SAAS-11326 # was caused by resized repeats, where empty string tokens were # inserted rather than no element. # This check can be removed when repeats handle resizing. return None for k , v in form . items ( ) : if isinstance ( v , dict ) : ret = _find_path_to_question_id ( v , attachment_name , use_basename = use_basename ) if ret : return [ k ] + ret elif isinstance ( v , list ) : for repeat in v : ret = _find_path_to_question_id ( repeat , attachment_name , use_basename = use_basename ) if ret : return [ k ] + ret else : if use_basename and os . path . isabs ( v ) : # only worth using basename if path is absolute since that is the edge case this attempts to solve v = os . path . basename ( v ) if v == attachment_name : return [ k ] return None