server/repository.py
branchstable
changeset 2929 51cdfe069e10
parent 2875 b7399ef8b3e0
child 2931 17224e90a1c4
child 2959 daabb9bc5233
equal deleted inserted replaced
2928:edfdb69df6e8 2929:51cdfe069e10
   994         entity.set_eid(self.system_source.create_eid(session))
   994         entity.set_eid(self.system_source.create_eid(session))
   995         if server.DEBUG & server.DBG_REPO:
   995         if server.DEBUG & server.DBG_REPO:
   996             print 'ADD entity', etype, entity.eid, dict(entity)
   996             print 'ADD entity', etype, entity.eid, dict(entity)
   997         entity._is_saved = False # entity has an eid but is not yet saved
   997         entity._is_saved = False # entity has an eid but is not yet saved
   998         relations = []
   998         relations = []
   999         # if inlined relations are specified, fill entity's related cache to
   999         # init edited_attributes before calling before_add_entity hooks
  1000         # avoid unnecessary queries
  1000         entity.edited_attributes = set(entity)
       
  1001         if source.should_call_hooks:
       
  1002             self.hm.call_hooks('before_add_entity', etype, session, entity)
       
  1003         # XXX use entity.keys here since edited_attributes is not updated for
       
  1004         # inline relations
  1001         for attr in entity.keys():
  1005         for attr in entity.keys():
  1002             rschema = eschema.subject_relation(attr)
  1006             rschema = eschema.subject_relation(attr)
  1003             if not rschema.is_final(): # inlined relation
  1007             if not rschema.is_final(): # inlined relation
  1004                 relations.append((attr, entity[attr]))
  1008                 relations.append((attr, entity[attr]))
  1005         if source.should_call_hooks:
       
  1006             self.hm.call_hooks('before_add_entity', etype, session, entity)
       
  1007         entity.edited_attributes = set(entity)
       
  1008         entity.set_defaults()
  1009         entity.set_defaults()
  1009         entity.check(creation=True)
  1010         entity.check(creation=True)
  1010         source.add_entity(session, entity)
  1011         source.add_entity(session, entity)
  1011         if source.uri != 'system':
  1012         if source.uri != 'system':
  1012             extid = source.get_extid(entity)
  1013             extid = source.get_extid(entity)