# HG changeset patch # User Sylvain Thénault # Date 1358429991 -3600 # Node ID 353bbd17a8b619c42c414b9969fe7ec066f3b93e # Parent 9a6e80bfad9df2bbd89101b3fcf349d208f81fcc Improve entity json export (closes #2559931) Make output from __json_encode__ predictable; use it in the ejsonexport view. diff -r 9a6e80bfad9d -r 353bbd17a8b6 entity.py --- a/entity.py Thu Jan 17 14:40:57 2013 +0100 +++ b/entity.py Thu Jan 17 14:39:51 2013 +0100 @@ -539,8 +539,10 @@ """custom json dumps hook to dump the entity's eid which is not part of dict structure itself """ + self.complete() dumpable = self.cw_attr_cache.copy() dumpable['eid'] = self.eid + dumpable['__cwetype__'] = self.__regid__ return dumpable def cw_adapt_to(self, interface): diff -r 9a6e80bfad9d -r 353bbd17a8b6 web/views/json.py --- a/web/views/json.py Thu Jan 17 14:40:57 2013 +0100 +++ b/web/views/json.py Thu Jan 17 14:39:51 2013 +0100 @@ -111,12 +111,7 @@ title = _('json-entities-export-view') def call(self): - entities = [] - for entity in self.cw_rset.entities(): - entity.complete() # fetch all attributes - # hack to add extra metadata - entity.cw_attr_cache.update({ - '__cwetype__': entity.__regid__, - }) - entities.append(entity) - self.wdata(entities) + if self.cw_rset is None: + self.wdata([self.cw_extra_kwargs.get('entity')]) + else: + self.wdata(list(self.cw_rset.entities()))