[PATCH 07 of 18 seda] [entities] Fix ITree of simplified profile to return children properly ordered

Sylvain Thenault sylvain.thenault at logilab.fr
Mon Dec 11 16:53:39 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1512641139 -3600
#      Thu Dec 07 11:05:39 2017 +0100
# Node ID 626326fafee088abeaa54f5c70947c2133561cbd
# Parent  e1fe9adc6a0fc9c213195d91e615b1f36709f906
[entities] Fix ITree of simplified profile to return children properly ordered

based on reference's ordering attribute. Use the reference and not the data
object's ordering because it's the one used on the data objects tab for
simplified profiles.

diff --git a/cubicweb_seda/entities/itree.py b/cubicweb_seda/entities/itree.py
--- a/cubicweb_seda/entities/itree.py
+++ b/cubicweb_seda/entities/itree.py
@@ -107,11 +107,11 @@ class ITreeBaseSimplifiedArchiveUnitAdap
         for child in super(ITreeBaseSimplifiedArchiveUnitAdapter, self).iterchildren():
             yield child
         seq = self.entity.first_level_choice.content_sequence
         assert seq is not None, self.entity  # can't be None in simplified profile
         for do in self._cw.execute(
-                'Any DO, DOUA ORDERBY DOUA WHERE DO user_annotation DOUA, '
+                'Any DO, DOUA ORDERBY REFO WHERE DO user_annotation DOUA, REF ordering REFO, '
                 'REF seda_data_object_reference_id DO, '
                 'REF seda_data_object_reference SEQ, SEQ eid %(x)s',
                 {'x': seq.eid}).entities():
             yield do
 
diff --git a/test/test_entities.py b/test/test_entities.py
--- a/test/test_entities.py
+++ b/test/test_entities.py
@@ -232,31 +232,52 @@ class ITreeTC(CubicWebTC):
 
     def test(self):
         with self.admin_access.cnx() as cnx:
             transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'test profile')
             au, alt, seq = create_archive_unit(transfer)
+            au2 = create_archive_unit(transfer)[0]
             do_ref = cnx.create_entity('SEDADataObjectReference',
                                        seda_data_object_reference=seq)
             bdo = create_data_object(transfer,
                                      reverse_seda_data_object_reference_id=do_ref)
+            do_ref2 = cnx.create_entity('SEDADataObjectReference',
+                                        seda_data_object_reference=seq)
+            bdo2 = create_data_object(transfer,
+                                      reverse_seda_data_object_reference_id=do_ref2)
             cnx.commit()
 
-            self.assertChildren(transfer, [bdo.eid, au.eid])
+            self.assertChildren(transfer, [bdo.eid, bdo2.eid, au.eid, au2.eid])
             self.assertChildren(au, [])
             self.assertParent(transfer, None)
             self.assertParent(au, transfer.eid)
             self.assertParent(bdo, transfer.eid)
 
             transfer.cw_set(simplified_profile=True)
             cnx.commit()
 
-            self.assertChildren(transfer, [au.eid])
-            self.assertChildren(au, [bdo.eid])
+            self.assertChildren(transfer, [au.eid, au2.eid])
+            self.assertChildren(au, [bdo.eid, bdo2.eid])
             self.assertParent(transfer, None)
             self.assertParent(au, transfer.eid)
             self.assertParent(bdo, au.eid)
 
+            au.cw_set(ordering=2)
+            au2.cw_set(ordering=1)
+            bdo.cw_set(ordering=2)
+            bdo2.cw_set(ordering=1)
+            do_ref.cw_set(ordering=2)
+            do_ref2.cw_set(ordering=1)
+            cnx.commit()
+
+            self.assertChildren(transfer, [au2.eid, au.eid])
+            self.assertChildren(au, [bdo2.eid, bdo.eid])
+
+            transfer.cw_set(simplified_profile=False)
+            cnx.commit()
+
+            self.assertChildren(transfer, [bdo2.eid, bdo.eid, au2.eid, au.eid])
+
 
 class RuleFromETypeTC(unittest.TestCase):
     def test_rule_from_etype(self):
         for rule_type in ('access', 'appraisal', 'classification',
                           'reuse', 'dissemination', 'storage'):


More information about the saem-devel mailing list