[ui] Custom renderer should only be used in the context of a 'reference' archive unit
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 12 Jul 2016 10:45:57 +0200
changeset 1411 1ffc8d98bade
parent 1410 f15e2d29131d
child 1412 4ab284d9934d
[ui] Custom renderer should only be used in the context of a 'reference' archive unit SEDAArchiveUnitRefId may be used within the context of other kinds of reference, available from SEDAContent (IsPartOf, VersionOf, etc.).
views/archiveunit.py
--- a/views/archiveunit.py	Tue Jul 12 10:44:11 2016 +0200
+++ b/views/archiveunit.py	Tue Jul 12 10:45:57 2016 +0200
@@ -56,9 +56,13 @@
             entity = rset.get_entity(0, 0)
         if entity.cw_etype == 'SEDAArchiveUnit':
             entity = entity.first_level_choice
+        elif entity.cw_etype == 'SEDAArchiveUnitRefId':
+            entity = entity.seda_archive_unit_ref_id_from[0]
+            if entity.cw_etype != 'SEDAAltArchiveUnitArchiveUnitRefId':
+                return 0  # other kind of reference
         assert entity.cw_etype == 'SEDAAltArchiveUnitArchiveUnitRefId', \
-            ('is_archive_unit_ref can only be used in the context of a SEDAArchiveUnit '
-             'or SEDAAltArchiveUnitArchiveUnitRefId entity, not %s' % entity)
+            ('is_archive_unit_ref can only be used in the context of a SEDAArchiveUnit, '
+             'SEDAArchiveUnitRefId or SEDAAltArchiveUnitArchiveUnitRefId entity, not %s' % entity)
         return 0 if entity.content_sequence else 1
 
 
@@ -311,9 +315,10 @@
     """Custom inlined form renderer that doesn't display any title (nor remove link)
     """
     __select__ = (formrenderers.EntityInlinedFormRenderer.__select__
-                  & is_instance('SEDAAltArchiveUnitArchiveUnitRefId',
-                                'SEDAArchiveUnitRefId',
-                                'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement'))
+                  & (is_instance('SEDAAltArchiveUnitArchiveUnitRefId',
+                                 'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement')
+                     | (is_instance('SEDAArchiveUnitRefId')
+                        & is_archive_unit_ref())))
 
     def render_title(self, w, form, values):
         pass