'Extracts the common "which-format/serialize/return-response" cycle.
Mostly a useful shortcut/hook.'

def create_response(self, request, data, response_class=HttpResponse, response_objects=None, **response_kwargs):

    filtered_objects_ids = None
    if response_objects:
        filtered_objects_ids = [item.id for item in response_objects if request.user.has_perm('view_resourcebase', item.get_self_resource())]
    if (isinstance(data, dict) and ('objects' in data) and (not isinstance(data['objects'], list))):
        if filtered_objects_ids:
            data['objects'] = [x for x in list(self.format_objects(data['objects'])) if (x['id'] in filtered_objects_ids)]
        else:
            data['objects'] = list(self.format_objects(data['objects']))
    desired_format = self.determine_format(request)
    serialized = self.serialize(request, data, desired_format)
    return response_class(content=serialized, content_type=build_content_type(desired_format), **response_kwargs)
