[PATCH 2 of 2 seda] [predicates] Give extra context information from predicates to _seda_container_from_context

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Mar 17 10:43:40 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1489733775 -3600
#      Fri Mar 17 07:56:15 2017 +0100
# Node ID 55d886119a5af43195932876d91eef47f055caf9
# Parent  fb14664bb28e62a004853b8320c8f69f72583a90
[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.

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
@@ -72,13 +72,16 @@ def parent_and_container(entity):
         elif parent.cw_adapt_to('IContainer'):
             container = parent
     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
     if entity.cw_etype != 'SEDAArchiveTransfer':
         entity = parent_and_container(entity)[1]
@@ -88,29 +91,29 @@ def _seda_container_from_context(rset, e
 @objectify_predicate
 def component_unit(cls, req, rset=None, entity=None, **kwargs):
     """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':
         # XXX archive unit component, for now suppose it's "simplified"
         return 1
     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':
         # XXX archive unit component, for now suppose it's "simplified"
         return 0
@@ -118,11 +121,11 @@ def is_full_seda2_profile(entity=None, r
 
 
 @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):
     """Return the rule type (e.g. 'access') from an etype enclosing the information
     (e.g. 'SEDAAltAccessRulePreventInheritance', 'SEDASeqAaccessRuleRule' or 'SEDAAccessRule')


More information about the saem-devel mailing list