# HG changeset patch # User Sylvain Thénault # Date 1247144210 -7200 # Node ID b9e2c1b7b873436e0999424c713956c20d418809 # Parent acf4b6a59558e2dc64e9dff5a4fa5a474772ee95 rewrite test schema using a single schema file diff -r acf4b6a59558 -r b9e2c1b7b873 server/test/data/schema.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/test/data/schema.py Thu Jul 09 14:56:50 2009 +0200 @@ -0,0 +1,207 @@ +""" + +:organization: Logilab +:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. +:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr +:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses +""" +from cubicweb.schema import format_constraint + +class Affaire(WorkflowableEntityType): + permissions = { + 'read': ('managers', + ERQLExpression('X owned_by U'), ERQLExpression('X concerne S?, S owned_by U')), + 'add': ('managers', ERQLExpression('X concerne S, S owned_by U')), + 'update': ('managers', 'owners', ERQLExpression('X in_state S, S name in ("pitetre", "en cours")')), + 'delete': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')), + } + + ref = String(fulltextindexed=True, indexed=True, + constraints=[SizeConstraint(16)]) + sujet = String(fulltextindexed=True, + constraints=[SizeConstraint(256)]) + descr_format = String(meta=True, internationalizable=True, + default='text/rest', constraints=[format_constraint]) + descr = String(fulltextindexed=True, + description=_('more detailed description')) + + duration = Int() + invoiced = Int() + + depends_on = SubjectRelation('Affaire') + require_permission = SubjectRelation('CWPermission') + concerne = SubjectRelation(('Societe', 'Note')) + todo_by = SubjectRelation('Personne') + documented_by = SubjectRelation('Card') + + +class Societe(EntityType): + permissions = { + 'read': ('managers', 'users', 'guests'), + 'update': ('managers', 'owners', ERQLExpression('U login L, X nom L')), + 'delete': ('managers', 'owners', ERQLExpression('U login L, X nom L')), + 'add': ('managers', 'users',) + } + + nom = String(maxsize=64, fulltextindexed=True) + web = String(maxsize=128) + type = String(maxsize=128) # attribute in common with Note + tel = Int() + fax = Int() + rncs = String(maxsize=128) + ad1 = String(maxsize=128) + ad2 = String(maxsize=128) + ad3 = String(maxsize=128) + cp = String(maxsize=12) + ville= String(maxsize=32) + + +class Division(Societe): + __specializes_schema__ = True + +class SubDivision(Division): + __specializes_schema__ = True + travaille_subdivision = ObjectRelation('Personne') + +_euser = import_schema('base').CWUser +_euser.__relations__[0].fulltextindexed = True + +class Note(EntityType): + date = String(maxsize=10) + type = String(maxsize=6) + para = String(maxsize=512) + + migrated_from = SubjectRelation('Note') + attachment = SubjectRelation(('File', 'Image')) + inline1 = SubjectRelation('Affaire', inlined=True) + todo_by = SubjectRelation('CWUser') + +class Personne(EntityType): + nom = String(fulltextindexed=True, required=True, maxsize=64) + prenom = String(fulltextindexed=True, maxsize=64) + sexe = String(maxsize=1, default='M') + promo = String(vocabulary=('bon','pasbon')) + titre = String(fulltextindexed=True, maxsize=128) + adel = String(maxsize=128) + ass = String(maxsize=128) + web = String(maxsize=128) + tel = Int() + fax = Int() + datenaiss = Datetime() + test = Boolean() + description = String() + firstname = String(fulltextindexed=True, maxsize=64) + + travaille = SubjectRelation('Societe') + concerne = SubjectRelation('Affaire') + connait = SubjectRelation('Personne') + inline2 = SubjectRelation('Affaire', inlined=True) + comments = ObjectRelation('Comment') + + +class fiche(RelationType): + inlined = True + subject = 'Personne' + object = 'Card' + cardinality = '??' + +class multisource_inlined_rel(RelationType): + inlined = True + cardinality = '?*' + subject = ('Card', 'Note') + object = ('Affaire', 'Note') + +class ecrit_par(RelationType): + inlined = True + +class connait(RelationType): + symetric = True + +class concerne(RelationType): + permissions = { + 'read': ('managers', 'users', 'guests'), + 'add': ('managers', RRQLExpression('U has_update_permission S')), + 'delete': ('managers', RRQLExpression('O owned_by U')), + } + +class travaille(RelationType): + permissions = { + 'read': ('managers', 'users', 'guests'), + 'add': ('managers', RRQLExpression('U has_update_permission S')), + 'delete': ('managers', RRQLExpression('O owned_by U')), + } + +class para(AttributeRelationType): + 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): + permissions = {'read': ('managers', 'users', 'guests'), + 'delete': ('managers',), + 'add': ('managers',)} + + +class in_state(RelationDefinition): + subject = 'Note' + object = 'State' + cardinality = '1*' + constraints=[RQLConstraint('S is ET, O state_of ET')] + +class wf_info_for(RelationDefinition): + subject = 'TrInfo' + object = 'Note' + cardinality = '1*' + +class multisource_rel(RelationDefinition): + subject = ('Card', 'Note') + object = 'Note' + +class multisource_crossed_rel(RelationDefinition): + subject = ('Card', 'Note') + object = 'Note' + + +class see_also(RelationDefinition): + subject = ('Bookmark', 'Note') + object = ('Bookmark', 'Note') + +class evaluee(RelationDefinition): + subject = ('Personne', 'CWUser', 'Societe') + object = ('Note') + +class ecrit_par_1(RelationDefinition): + name = 'ecrit_par' + subject = 'Note' + object ='Personne' + constraints = [RQLConstraint('E concerns P, X version_of P')] + +class ecrit_par_2(RelationDefinition): + name = 'ecrit_par' + subject = 'Note' + object ='CWUser' + +class see_also(RelationDefinition): + subject = object = 'Folder' + + +class copain(RelationDefinition): + subject = object = 'CWUser' + +class tags(RelationDefinition): + subject = 'Tag' + object = ('CWUser', 'CWGroup', 'State', 'Note', 'Card', 'Affaire') + +class filed_under(RelationDefinition): + subject = ('Note', 'Affaire') + object = 'Folder' + +class require_permission(RelationDefinition): + subject = ('Card', 'Note') + object = 'CWPermission' + +class require_state(RelationDefinition): + subject = 'CWPermission' + object = 'State' diff -r acf4b6a59558 -r b9e2c1b7b873 server/test/data/schema/Affaire.py --- a/server/test/data/schema/Affaire.py Thu Jul 09 13:04:28 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -""" - -:organization: Logilab -:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. -:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr -:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses -""" -from cubicweb.schema import format_constraint - -class Affaire(WorkflowableEntityType): - permissions = { - 'read': ('managers', - ERQLExpression('X owned_by U'), ERQLExpression('X concerne S?, S owned_by U')), - 'add': ('managers', ERQLExpression('X concerne S, S owned_by U')), - 'update': ('managers', 'owners', ERQLExpression('X in_state S, S name in ("pitetre", "en cours")')), - 'delete': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')), - } - - ref = String(fulltextindexed=True, indexed=True, - constraints=[SizeConstraint(16)]) - sujet = String(fulltextindexed=True, - constraints=[SizeConstraint(256)]) - descr_format = String(meta=True, internationalizable=True, - default='text/rest', constraints=[format_constraint]) - descr = String(fulltextindexed=True, - description=_('more detailed description')) - - duration = Int() - invoiced = Int() - - depends_on = SubjectRelation('Affaire') - require_permission = SubjectRelation('CWPermission') - -class concerne(RelationType): - permissions = { - 'read': ('managers', 'users', 'guests'), - 'add': ('managers', RRQLExpression('U has_update_permission S')), - 'delete': ('managers', RRQLExpression('O owned_by U')), - } - - diff -r acf4b6a59558 -r b9e2c1b7b873 server/test/data/schema/Note.sql --- a/server/test/data/schema/Note.sql Thu Jul 09 13:04:28 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -date varchar(10) -type char(6) -para varchar(512) diff -r acf4b6a59558 -r b9e2c1b7b873 server/test/data/schema/Personne.sql --- a/server/test/data/schema/Personne.sql Thu Jul 09 13:04:28 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -nom ivarchar(64) NOT NULL -prenom ivarchar(64) -sexe char(1) DEFAULT 'M' -promo choice('bon','pasbon') -titre ivarchar(128) -adel varchar(128) -ass varchar(128) -web varchar(128) -tel integer -fax integer -datenaiss datetime -test boolean -description text -firstname ivarchar(64) diff -r acf4b6a59558 -r b9e2c1b7b873 server/test/data/schema/Societe.py --- a/server/test/data/schema/Societe.py Thu Jul 09 13:04:28 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -""" - -:organization: Logilab -:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. -:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr -:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses -""" -class Societe(EntityType): - permissions = { - 'read': ('managers', 'users', 'guests'), - 'update': ('managers', 'owners', ERQLExpression('U login L, X nom L')), - 'delete': ('managers', 'owners', ERQLExpression('U login L, X nom L')), - 'add': ('managers', 'users',) - } - - nom = String(maxsize=64, fulltextindexed=True) - web = String(maxsize=128) - type = String(maxsize=128) # attribute in common with Note - tel = Int() - fax = Int() - rncs = String(maxsize=128) - ad1 = String(maxsize=128) - ad2 = String(maxsize=128) - ad3 = String(maxsize=128) - cp = String(maxsize=12) - ville= String(maxsize=32) - - -class travaille(RelationType): - permissions = { - 'read': ('managers', 'users', 'guests'), - 'add': ('managers', RRQLExpression('U has_update_permission S')), - 'delete': ('managers', RRQLExpression('O owned_by U')), - } - - -class Division(Societe): - __specializes_schema__ = True - -class SubDivision(Division): - __specializes_schema__ = True - travaille_subdivision = ObjectRelation('Personne') diff -r acf4b6a59558 -r b9e2c1b7b873 server/test/data/schema/custom.py --- a/server/test/data/schema/custom.py Thu Jul 09 13:04:28 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -""" - -:organization: Logilab -:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. -:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr -:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses -""" - - -class test(AttributeRelationType): - permissions = {'read': ('managers', 'users', 'guests'), - 'delete': ('managers',), - 'add': ('managers',)} - -class fiche(RelationType): - inlined = True - subject = 'Personne' - object = 'Card' - cardinality = '??' - -class multisource_rel(RelationDefinition): - subject = ('Card', 'Note') - object = 'Note' - -class multisource_crossed_rel(RelationDefinition): - subject = ('Card', 'Note') - object = 'Note' - -class multisource_inlined_rel(RelationType): - inlined = True - cardinality = '?*' - subject = ('Card', 'Note') - object = ('Affaire', 'Note') - - -class see_also(RelationDefinition): - subject = ('Bookmark', 'Note') - object = ('Bookmark', 'Note') - -_euser = import_schema('base').CWUser -_euser.__relations__[0].fulltextindexed = True diff -r acf4b6a59558 -r b9e2c1b7b873 server/test/data/schema/note.py --- a/server/test/data/schema/note.py Thu Jul 09 13:04:28 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -""" - -:organization: Logilab -:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. -:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr -:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses -""" - -class para(AttributeRelationType): - 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 in_state(RelationDefinition): - subject = 'Note' - object = 'State' - cardinality = '1*' - constraints=[RQLConstraint('S is ET, O state_of ET')] - -class wf_info_for(RelationDefinition): - subject = 'TrInfo' - object = 'Note' - cardinality = '1*' diff -r acf4b6a59558 -r b9e2c1b7b873 server/test/data/schema/relations.rel --- a/server/test/data/schema/relations.rel Thu Jul 09 13:04:28 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -Personne travaille Societe -Personne evaluee Note -CWUser evaluee Note -Societe evaluee Note -Personne concerne Affaire -Affaire concerne Societe -Affaire concerne Note - -Note ecrit_par Personne inline CONSTRAINT E concerns P, X version_of P -Note ecrit_par CWUser inline CONSTRAINT -Personne connait Personne symetric - -# not inlined intentionaly -Comment comments Personne - -Note inline1 Affaire inline -Personne inline2 Affaire inline - -Note todo_by CWUser -Affaire todo_by Personne - -Folder see_also Folder - - -Affaire documented_by Card - -CWUser copain CWUser - -Tag tags CWUser -Tag tags CWGroup -Tag tags State -Tag tags Note -Tag tags Card -Tag tags Affaire - -Note filed_under Folder -Affaire filed_under Folder - -Card require_permission CWPermission -Note require_permission CWPermission -Personne require_permission CWPermission - -CWPermission require_state State - -Note migrated_from Note - -Note attachment File -Note attachment Image