[IMP] doc/backend: add example using jsonrpclib

This commit is contained in:
Raphael Collet 2014-09-09 10:12:00 +02:00
parent ab3ec1ef6c
commit 7190bb7886
1 changed files with 26 additions and 1 deletions

View File

@ -1752,7 +1752,7 @@ JSON-RPC Library
----------------
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 random
@ -1788,6 +1788,31 @@ with the libraries ``urllib2`` and ``json``::
}
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.
.. note::