[PATCH 3 of 4 seda] [entitites] Enhance simplified_profile predicate

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Apr 21 17:53:27 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1492783711 -7200
#      Fri Apr 21 16:08:31 2017 +0200
# Node ID 7d5eca4471582ba10863b8c295bf420701bf99bf
# Parent  9705a695191b6b698e512aa4532903aed954a5fb
[entitites] Enhance simplified_profile predicate

vs creation of component archive unit, in which case it should return a positive
score, not zero. This is because in such case, container can't be detected and
implementation trapped this and returned 0. In such case, we must check if we're
creating an archive unit and return 1 if so.

Closes extranet #18337031

diff --git a/cubicweb_seda/entities/__init__.py b/cubicweb_seda/entities/__init__.py
--- a/cubicweb_seda/entities/__init__.py
+++ b/cubicweb_seda/entities/__init__.py
@@ -100,10 +100,16 @@ def component_unit(cls, req, rset=None, 
 @objectify_predicate
 def simplified_profile(cls, req, rset=None, entity=None, **kwargs):
     """Predicate returning 1 score if context entity is within a simplified profile."""
     container = _seda_container_from_context(rset, entity, **kwargs)
     if container is None:
+        # Detect creation of a component archive unit, which are supposed to be
+        # simplified. If we can't get a container and we're creating an archive
+        # unit, it must be an archive unit component (else it's parent container
+        # should have been retrieved)
+        if getattr(req, 'form', {}).get('etype') == 'SEDAArchiveUnit':
+            return 1
         return 0
     if container.cw_etype == 'SEDAArchiveUnit':
         # XXX archive unit component, for now suppose it's "simplified"
         return 1
     return 1 if container.simplified_profile else 0
diff --git a/test/test_entities.py b/test/test_entities.py
--- a/test/test_entities.py
+++ b/test/test_entities.py
@@ -202,10 +202,17 @@ class PredicatesTC(CubicWebTC):
             self.assertEqual(full_seda2_profile_pred(None, req, entity=being_created), 1)
             transfer.cw_set(simplified_profile=True)
             self.assertEqual(simplified_profile_pred(None, req, entity=transfer), 1)
             self.assertEqual(full_seda2_profile_pred(None, req, entity=transfer), 0)
 
+            req.form = {'etype': 'SEDAArchiveUnit'}
+            etype_vreg = req.vreg['etypes']
+            unit = etype_vreg.etype_class('SEDAArchiveUnit')(req)
+            self.assertEqual(simplified_profile_pred(None, req, entity=unit), 1)
+            entity = etype_vreg.etype_class('SEDASeqAltArchiveUnitArchiveUnitRefIdManagement')(req)
+            self.assertEqual(simplified_profile_pred(None, req, entity=entity), 1)
+
 
 class ITreeTC(CubicWebTC):
 
     def assertChildren(self, entity, expected_eids):
         itree = entity.cw_adapt_to('ITreeBase')


More information about the saem-devel mailing list