I am currently in dire need of creating a nice admin page for a LDAP addressbook, which should do some slightly unusual things with the data (like manipulating Postfix's virtual table).
Pyjamas is sort of a Python version of GWT and is bliss. Finally I can code HTML and JS in python ;-)
And Juno is refreshingly simple. Since the whole frontend is done by Pyjamas, all I needed is a way to route JSONRPC calls to python code and operate in the backend.
So, here are two useful snippets:
# This decorator decodes JSONRPC arguments as sent by Pyjamas to # Juno, and calls the target function with the decoded version. def JSONRemote(target): def wrapper(web,*args,**kwargs): postdata=web.input().keys() data = json.loads(postdata) id, method, params = data["id"],data["method"],[web,]+data["params"] kwargs['method']=method return target(*params,**kwargs) return wrapper
Using this, any plain juno method works as a JSONRPC method!
@route('/user') @JSONRemote def list(web,startwith='*',method=None): try: result=search(filter='(&(email@example.com)(sn=%s*))'%startwith) resp=JSONResponse(result) except ldap.LDAPError, e: resp=JSONResponse(None,e.desc) return resp
See? No JSON decoding. And no encoding either, because I am creating the response using this:
This is probably not a great implementation but it's good enough for me right now.