73 # entity have been created and deleted in the same transaction |
72 # entity have been created and deleted in the same transaction |
74 continue |
73 continue |
75 entity = session.entity_from_eid(eid) |
74 entity = session.entity_from_eid(eid) |
76 if not entity.created_by: |
75 if not entity.created_by: |
77 session.add_relation(eid, 'created_by', session.user.eid) |
76 session.add_relation(eid, 'created_by', session.user.eid) |
78 |
|
79 |
|
80 class SetIsHook(MetaDataHook): |
|
81 """create a new entity -> set is and is_instance_of relations |
|
82 |
|
83 those relations are inserted using sql so they are not hookable. |
|
84 """ |
|
85 __regid__ = 'setis' |
|
86 events = ('after_add_entity',) |
|
87 |
|
88 def __call__(self): |
|
89 if hasattr(self.entity, '_cw_recreating'): |
|
90 return |
|
91 session = self._cw |
|
92 entity = self.entity |
|
93 try: |
|
94 session.system_sql('INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)' |
|
95 % (entity.eid, eschema_eid(session, entity.e_schema))) |
|
96 except IndexError: |
|
97 # during schema serialization, skip |
|
98 return |
|
99 for eschema in entity.e_schema.ancestors() + [entity.e_schema]: |
|
100 session.system_sql('INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)' |
|
101 % (entity.eid, eschema_eid(session, eschema))) |
|
102 |
77 |
103 |
78 |
104 class SetOwnershipHook(MetaDataHook): |
79 class SetOwnershipHook(MetaDataHook): |
105 """create a new entity -> set owner and creator metadata""" |
80 """create a new entity -> set owner and creator metadata""" |
106 __regid__ = 'setowner' |
81 __regid__ = 'setowner' |