--- a/schema.py Thu Jul 23 15:16:49 2009 +0200
+++ b/schema.py Thu Jul 23 15:29:07 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
--- a/schemas/base.py Thu Jul 23 15:16:49 2009 +0200
+++ b/schemas/base.py Thu Jul 23 15:29:07 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
--- a/server/hooks.py Thu Jul 23 15:16:49 2009 +0200
+++ b/server/hooks.py Thu Jul 23 15:29:07 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"""
--- a/server/hooksmanager.py Thu Jul 23 15:16:49 2009 +0200
+++ b/server/hooksmanager.py Thu Jul 23 15:29:07 2009 +0200
@@ -251,7 +251,7 @@
raise NotImplementedError
class SystemHook(Hook):
- accepts = ('',)
+ accepts = ()
from logging import getLogger
from cubicweb import set_log_methods
--- a/server/schemahooks.py Thu Jul 23 15:16:49 2009 +0200
+++ b/server/schemahooks.py Thu Jul 23 15:29:07 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',
@@ -189,7 +189,7 @@
DeleteCWRTypeOp(session, name)
-class DelRelationDefOp(SchemaOperation):
+class DeleteRelationDefOp(SchemaOperation):
"""actually remove the relation definition from the application's schema"""
def commit_event(self):
subjtype, rtype, objtype = self.kobj
@@ -238,7 +238,7 @@
# if this is the last instance, drop associated relation type
if lastrel and not rteid in pendings:
execute('DELETE CWRType X WHERE X eid %(x)s', {'x': rteid}, 'x')
- DelRelationDefOp(session, (subjschema, rschema, objschema))
+ DeleteRelationDefOp(session, (subjschema, rschema, objschema))
# addition ####################################################################
@@ -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]
@@ -883,7 +883,7 @@
self.perm, erschema.type, self.group)
-class DelRQLExpressionPermissionOp(AddRQLExpressionPermissionOp):
+class DeleteRQLExpressionPermissionOp(AddRQLExpressionPermissionOp):
"""synchronize schema when a *_permission relation has been deleted from an rql expression"""
def commit_event(self):
@@ -919,7 +919,7 @@
else: # RQLExpression
expr = session.execute('Any EXPR WHERE X eid %(x)s, X expression EXPR',
{'x': object}, 'x')[0][0]
- DelRQLExpressionPermissionOp(session, perm, subject, expr)
+ DeleteRQLExpressionPermissionOp(session, perm, subject, expr)
def rebuild_infered_relations(session, subject, rtype, object):
--- a/server/test/data/schema.py Thu Jul 23 15:16:49 2009 +0200
+++ b/server/test/data/schema.py Thu Jul 23 15:29:07 2009 +0200
@@ -63,8 +63,8 @@
__specializes_schema__ = True
travaille_subdivision = ObjectRelation('Personne')
-_euser = import_schema('base').CWUser
-_euser.__relations__[0].fulltextindexed = True
+from cubicweb.schemas.base import CWUser
+CWUser.get_relations('login').next().fulltextindexed = True
class Note(EntityType):
date = String(maxsize=10)
@@ -131,14 +131,14 @@
'delete': ('managers', RRQLExpression('O owned_by U')),
}
-class para(AttributeRelationType):
+class para(RelationType):
permissions = {
'read': ('managers', 'users', 'guests'),
'add': ('managers', ERQLExpression('X in_state S, S name "todo"')),
'delete': ('managers', ERQLExpression('X in_state S, S name "todo"')),
}
-class test(AttributeRelationType):
+class test(RelationType):
permissions = {'read': ('managers', 'users', 'guests'),
'delete': ('managers',),
'add': ('managers',)}
--- a/server/test/unittest_hookhelper.py Thu Jul 23 15:16:49 2009 +0200
+++ b/server/test/unittest_hookhelper.py Thu Jul 23 15:29:07 2009 +0200
@@ -41,7 +41,7 @@
from cubicweb.server import hooks, schemahooks
session = self.session
op1 = hooks.DelayedDeleteOp(session)
- op2 = schemahooks.DelErdefOp(session)
+ op2 = schemahooks.DeleteRelationDefOp(session)
# equivalent operation generated by op2 but replace it here by op3 so we
# can check the result...
op3 = schemahooks.UpdateSchemaOp(session)
--- a/server/test/unittest_hooks.py Thu Jul 23 15:16:49 2009 +0200
+++ b/server/test/unittest_hooks.py Thu Jul 23 15:29:07 2009 +0200
@@ -6,9 +6,13 @@
"""
from logilab.common.testlib import TestCase, unittest_main
+
+from datetime import datetime
+
+from cubicweb import (ConnectionError, RepositoryError, ValidationError,
+ AuthenticationError, BadConnectionId)
from cubicweb.devtools.apptest import RepositoryBasedTC, get_versions
-from cubicweb import ConnectionError, RepositoryError, ValidationError, AuthenticationError, BadConnectionId
from cubicweb.server.sqlutils import SQL_PREFIX
from cubicweb.server.repository import Repository
@@ -265,8 +269,8 @@
self.failIf(schema.has_entity('Societe2'))
self.failIf(schema.has_entity('concerne2'))
# schema should be update on insertion (after commit)
- self.execute('INSERT CWEType X: X name "Societe2", X description "", X meta FALSE, X final FALSE')
- self.execute('INSERT CWRType X: X name "concerne2", X description "", X meta FALSE, X final FALSE, X symetric FALSE')
+ self.execute('INSERT CWEType X: X name "Societe2", X description "", X final FALSE')
+ self.execute('INSERT CWRType X: X name "concerne2", X description "", X final FALSE, X symetric FALSE')
self.failIf(schema.has_entity('Societe2'))
self.failIf(schema.has_entity('concerne2'))
self.execute('SET X read_permission G WHERE X is CWEType, X name "Societe2", G is CWGroup')
@@ -614,5 +618,39 @@
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]
+ creation_date, modification_date = self.execute('Any CD, MD WHERE X eid %s, '
+ 'X creation_date CD, '
+ 'X modification_date MD' % eid)[0]
+ self.assertEquals((creation_date - _now).seconds, 0)
+ self.assertEquals((modification_date - _now).seconds, 0)
+
+ def test_metadata__date(self):
+ _now = datetime.now()
+ eid = self.execute('INSERT Note X')[0][0]
+ creation_date = self.execute('Any D WHERE X eid %s, X creation_date D' % eid)[0][0]
+ self.assertEquals((creation_date - _now).seconds, 0)
+
+ def test_metadata_created_by(self):
+ eid = self.execute('INSERT Note X')[0][0]
+ self.commit() # fire operations
+ rset = self.execute('Any U WHERE X eid %s, X created_by U' % eid)
+ self.assertEquals(len(rset), 1) # make sure we have only one creator
+ self.assertEquals(rset[0][0], self.session.user.eid)
+
+ def test_metadata_owned_by(self):
+ eid = self.execute('INSERT Note X')[0][0]
+ self.commit() # fire operations
+ rset = self.execute('Any U WHERE X eid %s, X owned_by U' % eid)
+ self.assertEquals(len(rset), 1) # make sure we have only one owner
+ self.assertEquals(rset[0][0], self.session.user.eid)
+
if __name__ == '__main__':
unittest_main()
--- a/test/unittest_schema.py Thu Jul 23 15:16:49 2009 +0200
+++ b/test/unittest_schema.py Thu Jul 23 15:29:07 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',