[PATCH 1 of 5 saem_ref] [ark] Extract a direct_naa_what function out of DirectArkNAALocator adapter

Denis Laxalde denis.laxalde at logilab.fr
Wed Apr 11 16:30:05 CEST 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1523441162 -7200
#      Wed Apr 11 12:06:02 2018 +0200
# Node ID e760c0a1d9b9745557512eec6b52d515e8d53d9a
# Parent  25079eeba4dd943ab4da1bfe2dcdf20d6ba30710
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r e760c0a1d9b9
# EXP-Topic ark-for-archiveunit
[ark] Extract a direct_naa_what function out of DirectArkNAALocator adapter

diff --git a/cubicweb_saem_ref/entities/__init__.py b/cubicweb_saem_ref/entities/__init__.py
--- a/cubicweb_saem_ref/entities/__init__.py
+++ b/cubicweb_saem_ref/entities/__init__.py
@@ -114,17 +114,21 @@ class ArkNAALocator(EntityAdapter):
         raise NotImplementedError()
 
 
+def direct_naa_what(entity):
+    # entity is usually not yet created, since ark has to be generated before entity creation
+    if 'ark_naa' in getattr(entity, 'cw_edited', {}):
+        return entity._cw.entity_from_eid(entity.cw_edited['ark_naa']).what
+    elif entity.ark_naa:
+        return entity.ark_naa[0].what
+    return None
+
+
 class DirectArkNAALocator(ArkNAALocator):
     """Return NAA specified through the ark_naa relation"""
     __select__ = relation_possible('ark_naa')
 
     def naa_what(self):
-        # entity is usually not yet created, since ark has to be generated before entity creation
-        if 'ark_naa' in getattr(self.entity, 'cw_edited', {}):
-            return self._cw.entity_from_eid(self.entity.cw_edited['ark_naa']).what
-        elif self.entity.ark_naa:
-            return self.entity.ark_naa[0].what
-        return None
+        return direct_naa_what(self.entity)
 
 
 class AgentArkNAALocator(ArkNAALocator):



More information about the saem-devel mailing list