[entities] update for cubicweb 3.22 (closes #9764961)
authorJulien Cristau <julien.cristau@logilab.fr>
Wed, 23 Dec 2015 16:02:27 +0100
changeset 1855 9af15350aaef
parent 1854 f1cb7556f384
child 1856 fedb66f3233c
[entities] update for cubicweb 3.22 (closes #9764961) The ejsonexport view no longer uses __json_encode__, we need to define adapters instead.
entities.py
--- a/entities.py	Tue Jan 05 14:42:24 2016 +0100
+++ b/entities.py	Wed Dec 23 16:02:27 2015 +0100
@@ -21,6 +21,12 @@
 from cubicweb.entities import AnyEntity, fetch_config
 from cubicweb.entities.adapters import IFTIndexableAdapter
 from cubicweb.predicates import has_related_entities, is_instance
+try:
+    from cubicweb.entities.adapters import ISerializableAdapter
+    from cubes.narval.entities import PlanSerializableAdapter
+    CW322 = True
+except ImportError:
+    CW322 = False
 
 from cubes.narval.entities import Plan
 
@@ -212,6 +218,20 @@
         return data
 
 
+if CW322:
+    class ProjectEnvironmentSerializableAdapter(ISerializableAdapter):
+        __select__ = is_instance('ProjectEnvironment')
+
+        def serialize(self):
+            entity = self.entity
+            data = super(ProjectEnvironmentSerializableAdapter, self).serialize()
+            data['apycot_process_environment'] = entity.apycot_process_environment()
+            if entity.repository:
+                data['repository'] = entity.repository.cw_adapt_to('ISerializable').serialize()
+            data['apycot_configuration'] = entity.apycot_configuration()
+            return data
+
+
 # Test configuration ###########################################################
 
 class TestConfig(RefinementMixIn, ExecutionRSSMixin, AnyEntity):
@@ -339,6 +359,16 @@
         return data
 
 
+if CW322:
+    class TestConfigSerializableAdapter(ISerializableAdapter):
+        __select__ = is_instance('TestConfig')
+
+        def serialize(self):
+            data = super(TestConfigSerializableAdapter, self).serialize()
+            data['apycot_process_environment'] = self.entity.apycot_process_environment()
+            return data
+
+
 class TestExecution(Plan, ExecutionRSSMixin):
     __regid__ = 'TestExecution'
 
@@ -470,6 +500,21 @@
             data['configuration'] = self.configuration.__json_encode__()
         return data
 
+
+if CW322:
+    class TestExecutionSerializableAdapter(PlanSerializableAdapter):
+        __select__ = is_instance('TestExecution')
+
+        def serialize(self):
+            entity = self.entity
+            data = super(TestExecutionSerializableAdapter, self).serialize()
+            if entity.environment:
+                data['environment'] = entity.environment.cw_adapt_to('ISerializable').serialize()
+            if entity.configuration:
+                data['configuration'] = entity.configuration.cw_adapt_to('ISerializable').serialize()
+            return data
+
+
 class CheckResult(AnyEntity):
     __regid__ = 'CheckResult'
     fetch_attrs, cw_fetch_order = fetch_config(['name', 'status'])