Commit 5c9e18bf authored by Arthur Lutz's avatar Arthur Lutz
Browse files

wip IFTIAdapter

parent 727f5c30d1c4
......@@ -16,3 +16,32 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""cubicweb-elasticsearch entity's classes"""
from cubicweb.entities.adapters import ISerializableAdapter
from cubicweb.predicates import is_instance
class IFTIAdapter(ISerializableAdapter):
"""Adapter to serialize an entity to a bare python structure that may be
directly serialized to e.g. JSON."""
__regid__ = 'IFTISerializable'
__select__ = is_instance('Any')
def serialize(self):
entity = self.entity
entity.complete()
data = {
'cw_etype': entity.cw_etype,
'cw_source': entity.cw_metainformation()['source']['uri'],
'eid': entity.eid,
}
for rschema, __ in entity.e_schema.attribute_definitions():
attr = rschema.type
try:
value = entity.cw_attr_cache[attr]
except KeyError:
# Bytes
pass
data[attr] = value
return data
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment