[Cubicweb] calling methods on remote objects [RFC]

Nicolas Chauvat nicolas.chauvat at logilab.fr
Thu Apr 2 09:10:02 CEST 2015

Hi List,

I am currently trying to develop a GUI in javascript that uses data
stored in several CubicWeb apps.

A reccurent problem I have is that the views are never quite the ones
I would like, but rewriting everything on the client side feels like
reinventing the wheel.

A simple example is for dc_title() and dc_long_title(). The classes in
entities on the server-side implement these methods, but I have no way
to access their result as JSON unless I implement a view specifically
to output it.

A better example is the cube timesheet and the method get_day_types()
of the entity Resource. There is some computation going on in there to
deal with calendar inheritance. There is even a json view that wraps
that method to wrap a part of the output in JSON. But if I want the
full result of that computation, I will have to add a new view and
deploy it on the server.

Should I really double each entity method with a view?

I am wondering if we could have some generic mechanism to call methods
on the entities of a resultset and return the output as JSON.

For example:

'Any X WHERE X is Version' with a call to dc_title() would output
{ [123, 'projectA 0.1.0'], [456, 'projectB 0.2.0'] }

'Any X WHERE X is Resource' with a call to get_day_types would output
{ [789, { '2015-01-01': ['dt_nonworking', 'validated'],
          '2015-01-02': ['dt_working', 'validated']}],
  [912, { '2015-01-01': ['dt_nonworking', 'validated'],
          '2015-01-02': ['dt_nonworking', 'pending]}],

I am not sure what the signature of the call could be... maybe one of
unless we want to try to include it in RQL and write something like
  Any X, Version.dc_title(X) WHERE X is Version
  Any X, Resource.get_day_types(X) WHERE X is Resource
or even
  Any X, X.dc_title() WHERE X is Version
  Any X, X.get_day_types() WHERE X is Resource

What do you think?

PS: You may note that the same kind of question can arise for
adapters: if I have an adapter on the server that can prepare my data
for a specific view, I may want to get its output directly instead of
reimplementing it on the client side. Maybe we do not have the right
set of concepts here and need some kind of generic filter/transform
functions callable directly from RQL. Maybe I am just looking for the
equivalent of SQL's stored procedures mixed with generic functions (hence
a matching of the signature/type to pick the right one depending on
the arguments) /me wonders...

Nicolas Chauvat

logilab.fr - services en informatique scientifique et gestion de connaissances  

More information about the Cubicweb mailing list