[PATCH eac] Add some generic left/right properties on the various kind of relations

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Mar 16 15:34:57 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1489674859 -3600
#      Thu Mar 16 15:34:19 2017 +0100
# Node ID eed500cfecb53e78aee95cd658db429ab3abdf2c
# Parent  11bb8cb5c00fca41e9b5d87bdca1a55d02abcfa7
Add some generic left/right properties on the various kind of relations

so they can be accessed consistently.

diff --git a/cubicweb_eac/entities.py b/cubicweb_eac/entities.py
--- a/cubicweb_eac/entities.py
+++ b/cubicweb_eac/entities.py
@@ -64,18 +64,53 @@ class AuthorityRecord(AnyEntity):
 class AgentKind(AnyEntity):
     __regid__ = 'AgentKind'
     fetch_attrs, cw_fetch_order = fetch_config(('name',))
 
 
-class ChronologicalRelation(AnyEntity):
-    __regid__ = 'ChronologicalRelation'
+class _Relation(AnyEntity):
 
     def dc_description(self):
         if self.description:
             return self.description
 
 
+class ChronologicalRelation(_Relation):
+    __regid__ = 'ChronologicalRelation'
+
+    @property
+    def left(self):
+        return self.chronological_predecessor[0]
+
+    @property
+    def right(self):
+        return self.chronological_successor[0]
+
+
+class AssociationRelation(_Relation):
+    __regid__ = 'AssociationRelation'
+
+    @property
+    def left(self):
+        return self.association_from[0]
+
+    @property
+    def right(self):
+        return self.association_to[0]
+
+
+class HierarchicalRelation(_Relation):
+    __regid__ = 'HierarchicalRelation'
+
+    @property
+    def left(self):
+        return self.hierarchical_parent[0]
+
+    @property
+    def right(self):
+        return self.hierarchical_child[0]
+
+
 class EACResourceRelation(AnyEntity):
     __regid__ = 'EACResourceRelation'
     fetch_attrs, cw_fetch_order = fetch_config(('agent_role', 'resource_role', 'description'))
 
     @property


More information about the saem-devel mailing list