'This method instantiates the correct subclass of XModuleDescriptor based
on the contents of json_data. It does not persist it and can create one which
has no usage id.
parent_xblock is used to compute inherited metadata as well as to append the new xblock.
json_data:
- \'block_type\': the xmodule block_type
- \'fields\': a dict of locally set fields (not inherited) in json format not pythonic typed format!
- \'definition\': the object id of the existing definition'

def create_xblock(self, runtime, course_key, block_type, block_id=None, fields=None, definition_id=None, parent_xblock=None, **kwargs):

    assert (runtime is not None)
    xblock_class = runtime.load_block_type(block_type)
    json_data = {'block_type': block_type, 'fields': {}}
    if (definition_id is not None):
        json_data['definition'] = definition_id
    if (parent_xblock is None):
        inherited_settings = {}
    else:
        inherited_settings = parent_xblock.xblock_kvs.inherited_settings.copy()
        if (fields is not None):
            for field_name in inheritance.InheritanceMixin.fields:
                if (field_name in fields):
                    inherited_settings[field_name] = fields[field_name]
    new_block = runtime.xblock_from_json(xblock_class, course_key, (BlockKey(block_type, block_id) if block_id else None), BlockData(**json_data), **kwargs)
    for (field_name, value) in (fields or {}).iteritems():
        setattr(new_block, field_name, value)
    if (parent_xblock is not None):
        parent_xblock.children.append(new_block.scope_ids.usage_id)
        parent_xblock.save()
    return new_block
