# HG changeset patch # User Adrien Di Mascio # Date 1248355721 -7200 # Node ID aa25d6b244c8212598cf70f0a6b2be27e27a0674 # Parent 5346d9f3d5ec0206cc2a6ecbfc4e722b9b6dd3fe new cwuri metadata + a few tests fixes on the way diff -r 5346d9f3d5ec -r aa25d6b244c8 schema.py --- a/schema.py Thu Jul 23 15:17:11 2009 +0200 +++ b/schema.py Thu Jul 23 15:28:41 2009 +0200 @@ -36,7 +36,7 @@ # set of meta-relations available for every entity types META_RELATIONS_TYPES = set(( 'owned_by', 'created_by', 'is', 'is_instance_of', 'identity', - 'eid', 'creation_date', 'modification_date', 'has_text', + 'eid', 'creation_date', 'modification_date', 'has_text', 'cwuri', )) # set of entity and relation types used to build the schema diff -r 5346d9f3d5ec -r aa25d6b244c8 schemas/base.py --- a/schemas/base.py Thu Jul 23 15:17:11 2009 +0200 +++ b/schemas/base.py Thu Jul 23 15:28:41 2009 +0200 @@ -131,6 +131,12 @@ subject = '*' object = 'Datetime' +class cwuri(RelationType): + """internal entity uri""" + cardinality = '11' + subject = '**' + object = 'String' + class CWProperty(EntityType): """used for cubicweb configuration. Once a property has been created you diff -r 5346d9f3d5ec -r aa25d6b244c8 server/hooks.py --- a/server/hooks.py Thu Jul 23 15:17:11 2009 +0200 +++ b/server/hooks.py Thu Jul 23 15:28:41 2009 +0200 @@ -33,6 +33,8 @@ entity['creation_date'] = datetime.now() if not 'modification_date' in entity: entity['modification_date'] = datetime.now() + if not 'cwuri' in entity: + entity['cwuri'] = session.base_url() + u'eid/%s' % entity.eid def setmtime_before_update_entity(session, entity): """update an entity -> set modification date""" diff -r 5346d9f3d5ec -r aa25d6b244c8 server/schemahooks.py --- a/server/schemahooks.py Thu Jul 23 15:17:11 2009 +0200 +++ b/server/schemahooks.py Thu Jul 23 15:28:41 2009 +0200 @@ -26,7 +26,7 @@ # core entity and relation types which can't be removed CORE_ETYPES = list(BASE_TYPES) + ['CWEType', 'CWRType', 'CWUser', 'CWGroup', 'CWConstraint', 'CWAttribute', 'CWRelation'] -CORE_RTYPES = ['eid', 'creation_date', 'modification_date', +CORE_RTYPES = ['eid', 'creation_date', 'modification_date', 'cwuri', 'login', 'upassword', 'name', 'is', 'instanceof', 'owned_by', 'created_by', 'in_group', 'relation_type', 'from_entity', 'to_entity', @@ -283,7 +283,7 @@ prefix=SQL_PREFIX) relrqls = [] for rtype in ('is', 'is_instance_of', 'creation_date', 'modification_date', - 'created_by', 'owned_by'): + 'cwuri', 'created_by', 'owned_by'): rschema = schema[rtype] sampletype = rschema.subjects()[0] desttype = rschema.objects()[0] diff -r 5346d9f3d5ec -r aa25d6b244c8 server/test/unittest_hooks.py --- a/server/test/unittest_hooks.py Thu Jul 23 15:17:11 2009 +0200 +++ b/server/test/unittest_hooks.py Thu Jul 23 15:28:41 2009 +0200 @@ -618,6 +618,11 @@ self.failUnless(cu.execute("INSERT Note X: X type 'a', X in_state S WHERE S name 'todo'")) cnx.commit() + def test_metadata_cwuri(self): + eid = self.execute('INSERT Note X')[0][0] + cwuri = self.execute('Any U WHERE X eid %s, X cwuri U' % eid)[0][0] + self.assertEquals(cwuri, self.repo.config['base-url'] + 'eid/%s' % eid) + def test_metadata_creation_modification_date(self): _now = datetime.now() eid = self.execute('INSERT Note X')[0][0] diff -r 5346d9f3d5ec -r aa25d6b244c8 test/unittest_schema.py --- a/test/unittest_schema.py Thu Jul 23 15:17:11 2009 +0200 +++ b/test/unittest_schema.py Thu Jul 23 15:28:41 2009 +0200 @@ -150,7 +150,7 @@ 'CWCache', 'CWConstraint', 'CWConstraintType', 'CWEType', 'CWAttribute', 'CWGroup', 'EmailAddress', 'CWRelation', 'CWPermission', 'CWProperty', 'CWRType', 'CWUser', - 'File', 'Float', 'Image', 'Int', 'Interval', 'Note', + 'ExternalUri', 'File', 'Float', 'Image', 'Int', 'Interval', 'Note', 'Password', 'Personne', 'RQLExpression', 'Societe', 'State', 'String', 'SubNote', 'Tag', 'Time', @@ -163,7 +163,7 @@ 'cardinality', 'comment', 'comment_format', 'composite', 'condition', 'connait', 'constrained_by', 'content', - 'content_format', 'created_by', 'creation_date', 'cstrtype', + 'content_format', 'created_by', 'creation_date', 'cstrtype', 'cwuri', 'data', 'data_encoding', 'data_format', 'defaultval', 'delete_permission', 'description', 'description_format', 'destination_state', @@ -179,7 +179,7 @@ 'label', 'last_login_time', 'login', - 'mainvars', 'meta', 'modification_date', + 'mainvars', 'modification_date', 'name', 'nom', @@ -193,7 +193,7 @@ 'tags', 'timestamp', 'title', 'to_entity', 'to_state', 'transition_of', 'travaille', 'type', - 'upassword', 'update_permission', 'use_email', + 'upassword', 'update_permission', 'uri', 'use_email', 'value', @@ -203,7 +203,7 @@ eschema = schema.eschema('CWUser') rels = sorted(str(r) for r in eschema.subject_relations()) - self.assertListEquals(rels, ['created_by', 'creation_date', 'eid', + self.assertListEquals(rels, ['created_by', 'creation_date', 'cwuri', 'eid', 'evaluee', 'firstname', 'has_text', 'identity', 'in_group', 'in_state', 'is', 'is_instance_of', 'last_login_time',