def add_resource_data(request, instance):
    """
    Helper function to add resource infomation to the request. This info can
    be used later on in the view context.

    The resource data is populated with the single instance that is created,
    updated or deleted (and does not include other resources modifed as a
    result).

    Resource data will only be populated if a RESOURCE and/or RESOURCE_ID is
    available on the specific model instance.
    """
    try:
        resource = getattr(instance, 'RESOURCE')
    except AttributeError:
        return
    request._resource = resource
    try:
        field = getattr(instance, 'RESOURCE_ID')
        resource_id = getattr(instance, field)
    except AttributeError:
        return
    request._resource_id = str(resource_id)
