author Sylvain Thénault <>
Tue, 05 Dec 2017 13:47:54 +0100
changeset 2896 ce08a5c6e100
child 2921 ad4051ee66b9
permissions -rw-r--r--
[schema] Add a new 'ordering' attribute on some etype + hook to set it autonomatically in order to being able to order children elements of an entity.

from cubicweb_seda.xsd2yams import MULTIPLE_CHILDREN


parent_rtypes = [rtype for _, rtype in MULTIPLE_CHILDREN]

for rtype in parent_rtypes:
    for peid, in rql('Any P GROUPBY P WHERE X {} P HAVING COUNT(X) > 1'.format(rtype)):
        for idx, child in enumerate(rql('Any X WHERE X {} P, P eid %(p)s'.format(rtype),
                                    {'p': peid}).entities()):
            child.cw_set(ordering=idx + 1)

rql('SET X ordering 1 WHERE X ordering NULL')