[IMP] doc/backend: add example using jsonrpclib
This commit is contained in:
parent
ab3ec1ef6c
commit
7190bb7886
|
@ -1752,7 +1752,7 @@ JSON-RPC Library
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
The following example is a Python program that interacts with an Odoo server
|
The following example is a Python program that interacts with an Odoo server
|
||||||
with the libraries ``urllib2`` and ``json``::
|
with the standard Python libraries ``urllib2`` and ``json``::
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
|
@ -1788,6 +1788,31 @@ with the libraries ``urllib2`` and ``json``::
|
||||||
}
|
}
|
||||||
idea_id = call(url, "object", "execute", DB, uid, PASS, 'idea.idea', 'create', args)
|
idea_id = call(url, "object", "execute", DB, uid, PASS, 'idea.idea', 'create', args)
|
||||||
|
|
||||||
|
Here is the same program, using the library
|
||||||
|
`jsonrpclib <https://pypi.python.org/pypi/jsonrpclib>`::
|
||||||
|
|
||||||
|
import jsonrpclib
|
||||||
|
|
||||||
|
# server proxy object
|
||||||
|
url = "http://%s:%s/jsonrpc" % (HOST, PORT)
|
||||||
|
server = jsonrpclib.Server(url)
|
||||||
|
|
||||||
|
# log in the given database
|
||||||
|
uid = server.call(service="common", method="login", args=[DB, USER, PASS])
|
||||||
|
|
||||||
|
# helper function for invoking model methods
|
||||||
|
def invoke(model, method, *args):
|
||||||
|
args = [DB, uid, PASS, model, method] + list(args)
|
||||||
|
return server.call(service="object", method="execute", args=args)
|
||||||
|
|
||||||
|
# create a new idea
|
||||||
|
args = {
|
||||||
|
'name' : 'Another idea',
|
||||||
|
'description' : 'This is another idea of mine',
|
||||||
|
'inventor_id': uid,
|
||||||
|
}
|
||||||
|
idea_id = invoke('idea.idea', 'create', args)
|
||||||
|
|
||||||
Examples can be easily adapted from XML-RPC to JSON-RPC.
|
Examples can be easily adapted from XML-RPC to JSON-RPC.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
Loading…
Reference in New Issue