Introduce a specific ITreeBase adapter for archive unit of simplified profiles
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 26 Aug 2016 08:14:16 +0200
changeset 1556 347aa6ee8338
parent 1555 d1c4f5a8fc8a
child 1557 789ccdadf81d
Introduce a specific ITreeBase adapter for archive unit of simplified profiles
entities/itree.py
--- a/entities/itree.py	Thu Aug 25 17:27:58 2016 +0200
+++ b/entities/itree.py	Fri Aug 26 08:14:16 2016 +0200
@@ -18,6 +18,8 @@
 from cubicweb.predicates import is_instance
 from cubicweb.view import EntityAdapter
 
+from cubes.seda.entities import simplified_profile
+
 
 def parent_archive_unit(entity):
     """Return the first encountered parent which is an ArchiveUnit"""
@@ -87,13 +89,23 @@
         for rel, role in [('seda_content', 'object'), ('seda_archive_unit', 'object')]:
             for child in seq.related(rel, role, entities=True):
                 yield child
-        if self.entity.container[0].simplified_profile:
-            for do in self._cw.execute(
-                    'Any DO, DOID ORDERBY DOID WHERE DO id DOID, '
-                    'REF seda_data_object_reference_id DO, '
-                    'REF seda_data_object_reference SEQ, SEQ eid %(x)s',
-                    {'x': seq.eid}).entities():
-                yield do
+
+
+class ITreeBaseSimplifiedArchiveUnitAdapter(ITreeBaseArchiveUnitAdapter):
+
+    __select__ = ITreeBaseArchiveUnitAdapter.__select__ & simplified_profile()
+
+    def iterchildren(self):
+        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, DOID ORDERBY DOID WHERE DO id DOID, '
+                'REF seda_data_object_reference_id DO, '
+                'REF seda_data_object_reference SEQ, SEQ eid %(x)s',
+                {'x': seq.eid}).entities():
+            yield do
 
 
 class ITreeBaseContentAdapter(IContainedToITreeBase):