[PATCH 3 of 4 saem_ref] [seda] Hide "ark_naa" relation for "nested" SEDAArchiveUnit entities

Denis Laxalde denis.laxalde at logilab.fr
Mon May 14 17:30:57 CEST 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1526308155 -7200
#      Mon May 14 16:29:15 2018 +0200
# Node ID 03cc50b258bb113a5352a406da447772bc091c2d
# Parent  b352fcc08cb69e7c08cf05f08710e0a05b1b7b64
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 03cc50b258bb
# EXP-Topic CONSEJIRA-491
[seda] Hide "ark_naa" relation for "nested" SEDAArchiveUnit entities

When a SEDAArchiveUnit is related to another SEDAArchiveUnit or to a
SEDAArchiveTransfer through "seda_archive_unit" relation, it usually
inherits its ARK naa from its parent. So we hide the relation from
entity primary view and autoform in these cases. This is done through
derivation of base uicfg tags; in the case of autoform, we need a
special predicate to parse the __linkto form parameter and detect if we
are creating an "nested" entity or not.

CONSEJIRA-491

diff --git a/cubicweb_saem_ref/views/seda.py b/cubicweb_saem_ref/views/seda.py
--- a/cubicweb_saem_ref/views/seda.py
+++ b/cubicweb_saem_ref/views/seda.py
@@ -15,6 +15,11 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-saem-ref views related to SEDA"""
 
+from cubicweb.predicates import (
+    has_related_entities,
+    is_instance,
+    objectify_predicate,
+)
 from cubicweb.web import formwidgets as fw
 from cubicweb.web.views import uicfg
 
@@ -52,6 +57,33 @@ affk.set_field_kwargs('SEDAArchiveUnit',
 archivetransfer.ArchiveTransferTabbedPrimaryView.tabs.append('saem.lifecycle_tab')
 
 
+ at objectify_predicate
+def creating_seda_archive_unit(cls, req, **kwargs):
+    for linkto in req.list_form_param('__linkto'):
+        rtype, _, role = linkto.split(':')
+        if (rtype, role) == ('seda_archive_unit', 'subject'):
+            return 1
+    return 0
+
+
+nested_archiveunit_afs = afs.derive(
+    __name__,
+    is_instance('SEDAArchiveUnit')
+    & (has_related_entities('seda_archive_unit')
+       | creating_seda_archive_unit())
+)
+nested_archiveunit_afs.tag_subject_of(('SEDAArchiveUnit', 'ark_naa', '*'),
+                                      'main', 'hidden')
+
+nested_archiveunit_pvs = pvs.derive(
+    __name__,
+    is_instance('SEDAArchiveUnit')
+    & has_related_entities('seda_archive_unit')
+)
+nested_archiveunit_pvs.tag_subject_of(('SEDAArchiveUnit', 'ark_naa', '*'),
+                                      'hidden')
+
+
 # Hide "identifiant pour le service versant" which should be automatically
 # filled.
 class SimplifiedContentMainView(archiveunit.SimplifiedContentMainView):



More information about the saem-devel mailing list