[R schema hooks] rename META_RELATIONS_TYPES into META_RTYPES, use it and other schema consts to avoid errors
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Sat, 01 Aug 2009 01:13:39 +0200
changeset 2617 89c62b855f2e
parent 2616 4501ee760eec
child 2618 ff9b0d5bd884
[R schema hooks] rename META_RELATIONS_TYPES into META_RTYPES, use it and other schema consts to avoid errors
server/migractions.py
server/schemahooks.py
web/views/schema.py
--- a/server/migractions.py	Sat Aug 01 00:01:12 2009 +0200
+++ b/server/migractions.py	Sat Aug 01 01:13:39 2009 +0200
@@ -30,7 +30,7 @@
 from yams.schema2sql import eschema2sql, rschema2sql
 
 from cubicweb import AuthenticationError, ETYPE_NAME_MAP
-from cubicweb.schema import VIRTUAL_RTYPES, CubicWebRelationSchema
+from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, CubicWebRelationSchema
 from cubicweb.dbapi import get_repository, repo_connect
 from cubicweb.common.migration import MigrationHelper, yes
 
@@ -587,7 +587,7 @@
         # register entity's attributes
         for rschema, attrschema in eschema.attribute_definitions():
             # ignore those meta relations, they will be automatically added
-            if rschema.type in ('eid', 'creation_date', 'modification_date'):
+            if rschema.type in META_RTYPES:
                 continue
             if not rschema.type in applschema:
                 # need to add the relation type and to commit to get it
@@ -603,7 +603,7 @@
             for rschema in eschema.subject_relations():
                 # attribute relation have already been processed and
                 # 'owned_by'/'created_by' will be automatically added
-                if rschema.final or rschema.type in ('owned_by', 'created_by', 'is', 'is_instance_of'):
+                if rschema.final or rschema.type in META_RTYPES:
                     continue
                 rtypeadded = rschema.type in applschema
                 for targetschema in rschema.objects(etype):
--- a/server/schemahooks.py	Sat Aug 01 00:01:12 2009 +0200
+++ b/server/schemahooks.py	Sat Aug 01 01:13:39 2009 +0200
@@ -17,6 +17,7 @@
 from yams.schema2sql import eschema2sql, rschema2sql, type_from_constraints
 
 from cubicweb import ValidationError, RepositoryError
+from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES
 from cubicweb.server import schemaserial as ss
 from cubicweb.server.sqlutils import SQL_PREFIX
 from cubicweb.server.pool import Operation, SingleLastOperation, PreCommitOperation
@@ -282,8 +283,7 @@
     tablesql = eschema2sql(session.pool.source('system').dbhelper, eschema,
                            prefix=SQL_PREFIX)
     relrqls = []
-    for rtype in ('is', 'is_instance_of', 'creation_date', 'modification_date',
-                  'cwuri', 'created_by', 'owned_by'):
+    for rtype in (META_RTYPES - VIRTUAL_RTYPES):
         rschema = schema[rtype]
         sampletype = rschema.subjects()[0]
         desttype = rschema.objects()[0]
@@ -300,7 +300,7 @@
     # or permission settings
     etype.eid = entity.eid
     AddCWETypeOp(session, etype)
-    # add meta creation_date, modification_date and owned_by relations
+    # add meta relations
     for rql, kwargs in relrqls:
         session.execute(rql, kwargs)
 
--- a/web/views/schema.py	Sat Aug 01 00:01:12 2009 +0200
+++ b/web/views/schema.py	Sat Aug 01 01:13:39 2009 +0200
@@ -13,7 +13,7 @@
 from yams import BASE_TYPES, schema2dot as s2d
 
 from cubicweb.selectors import implements, yes, match_user_groups
-from cubicweb.schema import META_RELATIONS_TYPES, SCHEMA_TYPES
+from cubicweb.schema import META_RTYPES, SCHEMA_TYPES
 from cubicweb.schemaviewer import SchemaViewer
 from cubicweb.view import EntityView, StartupView
 from cubicweb.common import tags, uilib
@@ -22,7 +22,7 @@
 from cubicweb.web.views import primary, baseviews, tabs, management
 
 ALWAYS_SKIP_TYPES = BASE_TYPES | SCHEMA_TYPES
-SKIP_TYPES = ALWAYS_SKIP_TYPES | META_RELATIONS_TYPES
+SKIP_TYPES = ALWAYS_SKIP_TYPES | META_RTYPES
 SKIP_TYPES.update(set(('Transition', 'State', 'TrInfo',
                        'CWUser', 'CWGroup',
                        'CWCache', 'CWProperty', 'CWPermission',
@@ -91,7 +91,7 @@
             relations = sorted(rschema for rschema in schema.relations()
                                if not (rschema.is_final()
                                        or rschema in skiptypes
-                                       or rschema in META_RELATIONS_TYPES))
+                                       or rschema in META_RTYPES))
         else:
             relations = []
         # index