'Find all fields of type reference and convert the payload into UsageKeys'

def _convert_reference_fields_to_keys(self, xblock):

    course_key = xblock.scope_ids.usage_id.course_key
    for field in xblock.fields.itervalues():
        if field.is_set_on(xblock):
            field_value = getattr(xblock, field.name)
            if (field_value is None):
                continue
            elif isinstance(field, Reference):
                setattr(xblock, field.name, self._make_usage_key(course_key, field_value))
            elif isinstance(field, ReferenceList):
                setattr(xblock, field.name, [self._make_usage_key(course_key, ele) for ele in field_value])
            elif isinstance(field, ReferenceValueDict):
                for (key, subvalue) in field_value.iteritems():
                    assert isinstance(subvalue, basestring)
                    field_value[key] = self._make_usage_key(course_key, subvalue)
                setattr(xblock, field.name, field_value)
