# HG changeset patch # User Sylvain Thénault # Date 1267778374 -3600 # Node ID 6c3d5f2a4e0141a7049c1f7b22997a3ec7c32d84 # Parent 3055dc7a7c8857f438aafa33ac74347f4b587e45 eschema_type_eid become eschema_eid and always get a schema as argument + misc cleanup diff -r 3055dc7a7c88 -r 6c3d5f2a4e01 hooks/metadata.py --- a/hooks/metadata.py Fri Mar 05 09:35:06 2010 +0100 +++ b/hooks/metadata.py Fri Mar 05 09:39:34 2010 +0100 @@ -14,9 +14,8 @@ from cubicweb.server import hook -def eschema_type_eid(session, etype): +def eschema_eid(session, eschema): """get eid of the CWEType entity for the given yams type""" - eschema = session.repo.schema.eschema(etype) # eschema.eid is None if schema has been readen from the filesystem, not # from the database (eg during tests) if eschema.eid is None: @@ -75,7 +74,10 @@ class SetIsHook(MetaDataHook): - """create a new entity -> set is relation""" + """create a new entity -> set is and is_instance_of relations + + those relations are inserted using sql so they are not hookable. + """ __regid__ = 'setis' events = ('after_add_entity',) @@ -85,18 +87,14 @@ session = self._cw entity = self.entity try: - #session.add_relation(entity.eid, 'is', - # eschema_type_eid(session, entity.__regid__)) session.system_sql('INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)' - % (entity.eid, eschema_type_eid(session, entity.__regid__))) + % (entity.eid, eschema_eid(session, entity.e_schema))) except IndexError: # during schema serialization, skip return - for etype in entity.e_schema.ancestors() + [entity.e_schema]: - #session.add_relation(entity.eid, 'is_instance_of', - # eschema_type_eid(session, etype)) + for eschema in entity.e_schema.ancestors() + [entity.e_schema]: session.system_sql('INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)' - % (entity.eid, eschema_type_eid(session, etype))) + % (entity.eid, eschema_eid(session, eschema))) class SetOwnershipHook(MetaDataHook):