[ui] Fix creation and tree display of 'reference' archive units
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 12 Jul 2016 10:44:11 +0200
changeset 1410 f15e2d29131d
parent 1409 19dd7d28374c
child 1411 1ffc8d98bade
[ui] Fix creation and tree display of 'reference' archive units
entities/itree.py
hooks.py
--- a/entities/itree.py	Tue Jul 12 10:11:13 2016 +0200
+++ b/entities/itree.py	Tue Jul 12 10:44:11 2016 +0200
@@ -80,8 +80,12 @@
 
     def iterchildren(self, entities=True, sametype=False):
         choice = self.entity.related('seda_alt_archive_unit_archive_unit_ref_id', 'subject').one()
-        seq = choice.related('seda_seq_alt_archive_unit_archive_unit_ref_id_management',
-                             'subject').one()
+        seq_rset = choice.related('seda_seq_alt_archive_unit_archive_unit_ref_id_management',
+                                  'subject')
+        if not seq_rset:
+            # 'reference' archive unit
+            return
+        seq = seq_rset.one()
         for rel, role in [('seda_content', 'object'), ('seda_archive_unit', 'object')]:
             for child in seq.related(rel, role, entities=True):
                 yield child
--- a/hooks.py	Tue Jul 12 10:11:13 2016 +0200
+++ b/hooks.py	Tue Jul 12 10:44:11 2016 +0200
@@ -116,7 +116,11 @@
         for entity in self.get_data():
             choice = entity.seda_alt_archive_unit_archive_unit_ref_id[0]
             seq = choice.content_sequence
+            if seq is None:
+                # 'reference' archive unit
+                continue
             if seq.reverse_seda_content:
+                # content is already set
                 continue
             content = self.cnx.create_entity('SEDAContent', seda_content=seq)
             self.cnx.create_entity('SEDATitle', seda_title=content)