[PATCH 2 of 3 eac V2] Add JsonAttrsMixin class for entities with json string attributes

Guillaume Vandevelde guillaume.vandevelde at logilab.fr
Mon Aug 19 15:30:17 CEST 2019


# HG changeset patch
# User Guillaume Vandevelde <gvandevelde at logilab.fr>
# Date 1566220108 -7200
#      Mon Aug 19 15:08:28 2019 +0200
# Node ID a6e392e15281f1dad5934b11f26e9694e674143d
# Parent  5399160e43df7b26039f112a74ad716558688d13
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r a6e392e15281
Add JsonAttrsMixin class for entities with json string attributes

diff -r 5399160e43df -r a6e392e15281 cubicweb_eac/entities.py
--- a/cubicweb_eac/entities.py	Mon Aug 19 15:03:38 2019 +0200
+++ b/cubicweb_eac/entities.py	Mon Aug 19 15:08:28 2019 +0200
@@ -112,7 +112,14 @@
         return self.hierarchical_child[0]
 
 
-class EACResourceRelation(AnyEntity):
+class JsonAttrsMixin(object):
+
+    @property
+    def json_attrs(self):
+        return json.loads(self.xml_attributes)
+
+
+class EACResourceRelation(AnyEntity, JsonAttrsMixin):
     __regid__ = 'EACResourceRelation'
     fetch_attrs, cw_fetch_order = fetch_config(('agent_role',
                                                 'attributes',
@@ -127,10 +134,6 @@
     def resource(self):
         return self.resource_relation_resource[0]
 
-    @property
-    def json_attrs(self):
-        return json.loads(self.xml_attributes)
-
     def dc_title(self):
         agent_title = self.record.dc_title()
         if self.agent_role:
@@ -143,7 +146,7 @@
                  'to': resource_title})
 
 
-class EACFunctionRelation(AnyEntity):
+class EACFunctionRelation(AnyEntity, JsonAttrsMixin):
     __regid__ = 'EACFunctionRelation'
     fetch_attrs, cw_fetch_order = fetch_config(('r_type',
                                                 'description',



More information about the saem-devel mailing list