[predicates] Give extra context information from predicates to _seda_container_from_context
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 17 Mar 2017 07:56:15 +0100
changeset 2503 55d886119a5a
parent 2502 fb14664bb28e
child 2512 93a52e1de95c
[predicates] Give extra context information from predicates to _seda_container_from_context as we may find there information about location of the entity within the result set.
cubicweb_seda/entities/__init__.py
--- a/cubicweb_seda/entities/__init__.py	Fri Mar 17 07:55:11 2017 +0100
+++ b/cubicweb_seda/entities/__init__.py	Fri Mar 17 07:56:15 2017 +0100
@@ -74,9 +74,12 @@
     return parent, container
 
 
-def _seda_container_from_context(rset, entity):
+def _seda_container_from_context(rset, entity, **kwargs):
     if entity is None:
-        entity = rset.one()
+        if 'row' in kwargs:
+            entity = rset.get_entity(kwargs['row'], kwargs.get('col', 0))
+        else:
+            entity = rset.one()
     # protect against unrelated entity types
     if not entity.cw_etype.startswith('SEDA'):
         return None
@@ -90,14 +93,14 @@
     """Predicate returning 1 score if context entity is within "component" archive unit (i.e.
     container root is not a SEDAArchiveTransfer but a SEDAArchiveUnit).
     """
-    entity = _seda_container_from_context(rset, entity)
+    entity = _seda_container_from_context(rset, entity, **kwargs)
     return 1 if entity.cw_etype == 'SEDAArchiveUnit' else 0
 
 
 @objectify_predicate
 def simplified_profile(cls, req, rset=None, entity=None, **kwargs):
     """Predicate returning 1 score if context entity is within a simplified profile."""
-    entity = _seda_container_from_context(rset, entity)
+    entity = _seda_container_from_context(rset, entity, **kwargs)
     if entity is None:
         return 0
     if entity.cw_etype == 'SEDAArchiveUnit':
@@ -106,9 +109,9 @@
     return 1 if entity.simplified_profile else 0
 
 
-def is_full_seda2_profile(entity=None, rset=None):
+def is_full_seda2_profile(entity=None, rset=None, **kwargs):
     """Return 1 if context entity is within a full seda2 profile, else 0."""
-    entity = _seda_container_from_context(rset, entity)
+    entity = _seda_container_from_context(rset, entity, **kwargs)
     if entity is None:
         return 1
     if entity.cw_etype == 'SEDAArchiveUnit':
@@ -120,7 +123,7 @@
 @objectify_predicate
 def full_seda2_profile(cls, req, rset=None, entity=None, **kwargs):
     """Predicate returning 1 score if context entity is within a full seda2 profile."""
-    return is_full_seda2_profile(entity, rset)
+    return is_full_seda2_profile(entity, rset, **kwargs)
 
 
 def rule_type_from_etype(etype):