Take the given value and start enrichment by object_type. The va

    Args:
        request (django.http.request.HttpRequest): request which is currently processed
        value (dict|list|django.db.models.Model):
            in case of django.db.models.Model object (or list of these
            objects), to_json method is invoked

    Returns:
        dict|list

def enrich_json_objects_by_object_type(request, value):
    """
    Take the given value and start enrichment by object_type. The va

    Args:
        request (django.http.request.HttpRequest): request which is currently processed
        value (dict|list|django.db.models.Model):
            in case of django.db.models.Model object (or list of these
            objects), to_json method is invoked

    Returns:
        dict|list
    """
    time_start_globally = time()
    if isinstance(value, list):
        json = [x.to_json() if hasattr(x, "to_json") else x for x in value]
    else:
        if isinstance(value, dict):
            json = value
        else:
            json = value.to_json()
    objects, nested = _collect_json_objects(json, by='object_type')
    for enricher_info in _get_OBJECT_TYPE_ENRICHER_ORDER():
        if len(enricher_info['object_types']) > 0:
            enricher_objects = flatten([objects.get(object_type, []) for object_type in enricher_info['object_types']])
            enricher_nested = any([nested.get(object_type, False) for object_type in enricher_info['object_types']])
        else:
            enricher_objects = flatten(objects.values())
            enricher_nested = any(nested.values())
        if len(enricher_objects) > 0:
            time_start = time()
            enricher_info['enricher'](request, enricher_objects, enricher_nested)
            LOGGER.debug('enrichment "{}" took {} seconds'.format(enricher_info['enricher_name'], time() - time_start))
            if not enricher_info['pure']:
                # if the enricher modified object types we must collect objects
                # again
                objects, nested = _collect_json_objects(json, by='object_type')
    LOGGER.debug('The whole enrichment of json objects by their object_type took {} seconds.'.format(time() - time_start_globally))
    return json