Locates a target container for the given portal_type and record

    :param record: The dictionary representation of a content object
    :type record: dict
    :returns: folder which contains the object
    :rtype: object

def find_target_container(portal_type, record):
    """Locates a target container for the given portal_type and record

    :param record: The dictionary representation of a content object
    :type record: dict
    :returns: folder which contains the object
    :rtype: object
    """
    portal_type = portal_type or record.get("portal_type")
    container = get_container_for(portal_type)
    if container:
        return container

    parent_uid = record.pop("parent_uid", None)
    parent_path = record.pop("parent_path", None)

    target = None

    # Try to find the target object
    if parent_uid:
        target = get_object_by_uid(parent_uid)
    elif parent_path:
        target = get_object_by_path(parent_path)
    else:
        fail(404, "No target UID/PATH information found")

    if not target:
        fail(404, "No target container found")

    return target