[dataimport] implement create_entity() on ObjectStore to provide a consistent interface stable
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 14 Feb 2011 17:46:08 +0100
branchstable
changeset 6990 353ad06867a8
parent 6989 4a999a647f52
child 6991 eb2ba251f093
child 6993 656561eddd1d
[dataimport] implement create_entity() on ObjectStore to provide a consistent interface (+fix typo s/attribute_edited/edited_attributed/)
dataimport.py
--- a/dataimport.py	Mon Feb 14 16:46:49 2011 +0100
+++ b/dataimport.py	Mon Feb 14 17:46:08 2011 +0100
@@ -306,11 +306,18 @@
         self.items.append(item)
         return len(self.items) - 1
 
-    def add(self, type, item):
+    def create_entity(self, etype, **data):
+        data['eid'] =  eid = self._put(etype, data)
+        self.eids[eid] = data
+        self.types.setdefault(etype, []).append(eid)
+        return data
+
+    @deprecated("[3.11] add is deprecated, use create_entity instead")
+    def add(self, etype, item):
         assert isinstance(item, dict), 'item is not a dict but a %s' % type(item)
-        eid = item['eid'] = self._put(type, item)
-        self.eids[eid] = item
-        self.types.setdefault(type, []).append(eid)
+        data = self.create_entity(etype, **item)
+        item['eid'] = data['eid']
+        return item
 
     def relate(self, eid_from, rtype, eid_to, inlined=False):
         """Add new relation"""
@@ -688,7 +695,7 @@
         del entity.cw_extra_kwargs
         entity.cw_edited = EditedEntity(entity)
         for attr in self.etype_attrs:
-            entity.cw_edited.attribute_edited(attr, self.generate(entity, attr))
+            entity.cw_edited.edited_attribute(attr, self.generate(entity, attr))
         rels = {}
         for rel in self.etype_rels:
             rels[rel] = self.generate(entity, rel)
@@ -697,7 +704,7 @@
     def init_entity(self, entity):
         entity.eid = self.source.create_eid(self.session)
         for attr in self.entity_attrs:
-            entity.cw_edited.attribute_edited(attr, self.generate(entity, attr))
+            entity.cw_edited.edited_attribute(attr, self.generate(entity, attr))
 
     def generate(self, entity, rtype):
         return getattr(self, 'gen_%s' % rtype)(entity)