eschema_type_eid become eschema_eid and always get a schema as argument + misc cleanup stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 05 Mar 2010 09:39:34 +0100
branchstable
changeset 4811 6c3d5f2a4e01
parent 4810 3055dc7a7c88
child 4812 2eb6a9b33aa5
child 4815 4ee224c4c41d
eschema_type_eid become eschema_eid and always get a schema as argument + misc cleanup
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):