(target_datum, source_datums)
return candidate
Find the datum in the list of source datums that best matches the target datum (if any)

    This uses the datums ID and case type to match. If 'additional_case_types' are in use then the matching
    can still work since the datums will have their case type set to their module's case type. A caveat
    here is that it is possible to link a form with multiple case types to a form that only supports
    one of the case types. This is not disabled since the app builder could configure conditional linking.
Find the datum in the list of source datums that best matches the target datum (if any)
Find the datum in the list of source datums that best matches the target datum ( if any )
def _find_best_match(target_datum, source_datums):
    """Find the datum in the list of source datums that best matches the target datum (if any)

    This uses the datums ID and case type to match. If 'additional_case_types' are in use then the matching
    can still work since the datums will have their case type set to their module's case type. A caveat
    here is that it is possible to link a form with multiple case types to a form that only supports
    one of the case types. This is not disabled since the app builder could configure conditional linking.
    """
    candidate = None
    for source_datum in source_datums:
        if isinstance(source_datum, WorkflowQueryMeta):
            continue
        if source_datum.from_parent_module:
            # if the datum is only there as a placeholder then we should ignore it
            continue
        if target_datum.id == source_datum.id:
            if source_datum.case_type and source_datum.case_type == target_datum.case_type:
                # same ID, same case type
                candidate = target_datum
                break
        else:
            if source_datum.case_type and source_datum.case_type == target_datum.case_type:
                # different ID, same case type
                candidate = target_datum.clone_to_match(source_id=source_datum.id)
                break

    return candidate
def _find_best_match ( target_datum , source_datums ) : candidate = None for source_datum in source_datums : if isinstance ( source_datum , WorkflowQueryMeta ) : continue if source_datum . from_parent_module : # if the datum is only there as a placeholder then we should ignore it continue if target_datum . id == source_datum . id : if source_datum . case_type and source_datum . case_type == target_datum . case_type : # same ID, same case type candidate = target_datum break else : if source_datum . case_type and source_datum . case_type == target_datum . case_type : # different ID, same case type candidate = target_datum . clone_to_match ( source_id = source_datum . id ) break return candidate