[Cubicweb] About IPrevNextAdapters and related

Adrien Di Mascio adrien.dimascio at logilab.fr
Mon Sep 17 08:17:34 CEST 2012


Hi Stéphane,

On 14/09/2012 09:33, Stéphane Bugat wrote:
> I was wondering if it was possible to use ITreeAdapters in some specific cases where there is actually no obvious tree relations.

ITreeAdapters are usually helpful when entities can be modeled with 
parent / child relations. In your case, I would say it doesn't fit.

> Let's imagine we have persons that are in contact using the relation "X in_contact_with Y". For a given person X, I want him to be able to navigate through its contacts Y. The problem is that X and Y are of the same types, so a tree relation has no sense here -- except if we could define that the "parent" entity is a kind of RQL result set... But it seems that we cannot define an ITreeAdapter with a simple "tree_relation" here.
>
> My question is: is it possible to define a specific IPrevNextAdapter in such cases? How could I select this Adapter not only on the instance (here ``is_instance('Person')``) but also on an RQL query (something like ``custom_rql = 'Any Y WHERE Y is Person, X is Person, X is_user U, X in_contact_with Y'`` where U is the current session user...)?
> Afterwards the previous_entity() and next_entity() will be very easy to define.

You can have a look at the tracker[1] cube and see how the 
IPrevNextAdapter for tickets is implemented. There is a crucial 
difference in your case, though : a ticket is part of a single version 
whereas a person can be part of several networks.

Don't know exactly what your application does, but you'd probably like 
to try and dive into d3.js[2] or one of its peer[3] who implement nice 
network visualization tools.

Adrien.

[1] 
http://hg.logilab.org/cubes/tracker/file/68ffac3d088f/views/ticket.py#l122

[2] https://github.com/mbostock/d3/wiki/Gallery
[3] http://selection.datavisualization.ch/

-- 
Adrien Di Mascio - LOGILAB, Paris (France).
Tél: 01.45.32.03.12
Formations - http://www.logilab.fr/formations
Développements - http://www.logilab.fr/services
Gestion de connaissances - http://www.cubicweb.org/



More information about the Cubicweb mailing list