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