server/test/data-schemaserial/schema.py
changeset 8945 ba9e3fbfa5a5
child 9452 5308b3fe03c9
equal deleted inserted replaced
8944:b167f039b6cb 8945:ba9e3fbfa5a5
       
     1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 
       
    19 from yams.buildobjs import (EntityType, RelationType, RelationDefinition,
       
    20                             SubjectRelation, RichString, String, Int, Float,
       
    21                             Boolean, Datetime, TZDatetime, Bytes)
       
    22 from yams.constraints import SizeConstraint
       
    23 from cubicweb.schema import (WorkflowableEntityType,
       
    24                              RQLConstraint, RQLUniqueConstraint,
       
    25                              ERQLExpression, RRQLExpression)
       
    26 
       
    27 from yams.buildobjs import make_type
       
    28 BabarTestType = make_type('BabarTestType')
       
    29 
       
    30 
       
    31 class Affaire(WorkflowableEntityType):
       
    32     __permissions__ = {
       
    33         'read':   ('managers',
       
    34                    ERQLExpression('X owned_by U'), ERQLExpression('X concerne S?, S owned_by U')),
       
    35         'add':    ('managers', ERQLExpression('X concerne S, S owned_by U')),
       
    36         'update': ('managers', 'owners', ERQLExpression('X in_state S, S name in ("pitetre", "en cours")')),
       
    37         'delete': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')),
       
    38         }
       
    39 
       
    40     ref = String(fulltextindexed=True, indexed=True,
       
    41                  constraints=[SizeConstraint(16)])
       
    42     sujet = String(fulltextindexed=True,
       
    43                    constraints=[SizeConstraint(256)])
       
    44     descr = RichString(fulltextindexed=True,
       
    45                        description=_('more detailed description'))
       
    46 
       
    47     duration = Int()
       
    48     invoiced = Float()
       
    49     opt_attr = Bytes()
       
    50 
       
    51     depends_on = SubjectRelation('Affaire')
       
    52     require_permission = SubjectRelation('CWPermission')
       
    53     concerne = SubjectRelation(('Societe', 'Note'))
       
    54     todo_by = SubjectRelation('Personne', cardinality='?*')
       
    55     documented_by = SubjectRelation('Card')
       
    56 
       
    57 
       
    58 class Societe(EntityType):
       
    59     __unique_together__ = [('nom', 'type', 'cp')]
       
    60     __permissions__ = {
       
    61         'read': ('managers', 'users', 'guests'),
       
    62         'update': ('managers', 'owners', ERQLExpression('U login L, X nom L')),
       
    63         'delete': ('managers', 'owners', ERQLExpression('U login L, X nom L')),
       
    64         'add': ('managers', 'users',)
       
    65         }
       
    66 
       
    67     nom  = String(maxsize=64, fulltextindexed=True)
       
    68     web  = String(maxsize=128)
       
    69     type  = String(maxsize=128) # attribute in common with Note
       
    70     tel  = Int()
       
    71     fax  = Int()
       
    72     rncs = String(maxsize=128)
       
    73     ad1  = String(maxsize=128)
       
    74     ad2  = String(maxsize=128)
       
    75     ad3  = String(maxsize=128)
       
    76     cp   = String(maxsize=12)
       
    77     ville= String(maxsize=32)
       
    78 
       
    79 
       
    80 class Division(Societe):
       
    81     __specializes_schema__ = True
       
    82 
       
    83 class SubDivision(Division):
       
    84     __specializes_schema__ = True
       
    85 
       
    86 class travaille_subdivision(RelationDefinition):
       
    87     subject = 'Personne'
       
    88     object = 'SubDivision'
       
    89 
       
    90 from cubicweb.schemas.base import CWUser
       
    91 CWUser.get_relations('login').next().fulltextindexed = True
       
    92 
       
    93 class Note(WorkflowableEntityType):
       
    94     date = String(maxsize=10)
       
    95     type = String(maxsize=6)
       
    96     para = String(maxsize=512,
       
    97                   __permissions__ = {
       
    98                       'read':   ('managers', 'users', 'guests'),
       
    99                       'update': ('managers', ERQLExpression('X in_state S, S name "todo"')),
       
   100                       })
       
   101 
       
   102     migrated_from = SubjectRelation('Note')
       
   103     attachment = SubjectRelation('File')
       
   104     inline1 = SubjectRelation('Affaire', inlined=True, cardinality='?*',
       
   105                               constraints=[RQLUniqueConstraint('S type T, S inline1 A1, A1 todo_by C, '
       
   106                                                               'Y type T, Y inline1 A2, A2 todo_by C',
       
   107                                                                'S,Y')])
       
   108     todo_by = SubjectRelation('CWUser')
       
   109 
       
   110 class Personne(EntityType):
       
   111     __unique_together__ = [('nom', 'prenom', 'inline2')]
       
   112     nom    = String(fulltextindexed=True, required=True, maxsize=64)
       
   113     prenom = String(fulltextindexed=True, maxsize=64)
       
   114     sexe   = String(maxsize=1, default='M', fulltextindexed=True)
       
   115     promo  = String(vocabulary=('bon','pasbon'))
       
   116     titre  = String(fulltextindexed=True, maxsize=128)
       
   117     adel   = String(maxsize=128)
       
   118     ass    = String(maxsize=128)
       
   119     web    = String(maxsize=128)
       
   120     tel    = Int()
       
   121     fax    = Int()
       
   122     datenaiss = Datetime()
       
   123     tzdatenaiss = TZDatetime()
       
   124     test   = Boolean(__permissions__={
       
   125         'read': ('managers', 'users', 'guests'),
       
   126         'update': ('managers',),
       
   127         })
       
   128     description = String()
       
   129     firstname = String(fulltextindexed=True, maxsize=64)
       
   130 
       
   131     concerne = SubjectRelation('Affaire')
       
   132     connait = SubjectRelation('Personne')
       
   133     inline2 = SubjectRelation('Affaire', inlined=True, cardinality='?*')
       
   134 
       
   135     custom_field_of_jungle = BabarTestType(jungle_speed=42)
       
   136 
       
   137 
       
   138 class Old(EntityType):
       
   139     name = String()
       
   140 
       
   141 
       
   142 class connait(RelationType):
       
   143     symmetric = True
       
   144 
       
   145 class concerne(RelationType):
       
   146     __permissions__ = {
       
   147         'read':   ('managers', 'users', 'guests'),
       
   148         'add':    ('managers', RRQLExpression('U has_update_permission S')),
       
   149         'delete': ('managers', RRQLExpression('O owned_by U')),
       
   150         }
       
   151 
       
   152 class travaille(RelationDefinition):
       
   153     __permissions__ = {
       
   154         'read':   ('managers', 'users', 'guests'),
       
   155         'add':    ('managers', RRQLExpression('U has_update_permission S')),
       
   156         'delete': ('managers', RRQLExpression('O owned_by U')),
       
   157         }
       
   158     subject = 'Personne'
       
   159     object = 'Societe'
       
   160 
       
   161 class comments(RelationDefinition):
       
   162     subject = 'Comment'
       
   163     object = 'Personne'
       
   164 
       
   165 class fiche(RelationDefinition):
       
   166     inlined = True
       
   167     subject = 'Personne'
       
   168     object = 'Card'
       
   169     cardinality = '??'
       
   170 
       
   171 class multisource_inlined_rel(RelationDefinition):
       
   172     inlined = True
       
   173     cardinality = '?*'
       
   174     subject = ('Card', 'Note')
       
   175     object = ('Affaire', 'Note')
       
   176 
       
   177 class multisource_rel(RelationDefinition):
       
   178     subject = ('Card', 'Note')
       
   179     object = 'Note'
       
   180 
       
   181 class multisource_crossed_rel(RelationDefinition):
       
   182     subject = ('Card', 'Note')
       
   183     object = 'Note'
       
   184 
       
   185 
       
   186 class see_also_1(RelationDefinition):
       
   187     name = 'see_also'
       
   188     subject = object = 'Folder'
       
   189 
       
   190 class see_also_2(RelationDefinition):
       
   191     name = 'see_also'
       
   192     subject = ('Bookmark', 'Note')
       
   193     object = ('Bookmark', 'Note')
       
   194 
       
   195 class evaluee(RelationDefinition):
       
   196     subject = ('Personne', 'CWUser', 'Societe')
       
   197     object = ('Note')
       
   198 
       
   199 class ecrit_par(RelationType):
       
   200     inlined = True
       
   201 
       
   202 class ecrit_par_1(RelationDefinition):
       
   203     name = 'ecrit_par'
       
   204     subject = 'Note'
       
   205     object ='Personne'
       
   206     constraints = [RQLConstraint('E concerns P, S version_of P')]
       
   207     cardinality = '?*'
       
   208 
       
   209 class ecrit_par_2(RelationDefinition):
       
   210     name = 'ecrit_par'
       
   211     subject = 'Note'
       
   212     object ='CWUser'
       
   213     cardinality='?*'
       
   214 
       
   215 
       
   216 class copain(RelationDefinition):
       
   217     subject = object = 'CWUser'
       
   218 
       
   219 class tags(RelationDefinition):
       
   220     subject = 'Tag'
       
   221     object = ('CWUser', 'CWGroup', 'State', 'Note', 'Card', 'Affaire')
       
   222 
       
   223 class filed_under(RelationDefinition):
       
   224     subject = ('Note', 'Affaire')
       
   225     object = 'Folder'
       
   226 
       
   227 class require_permission(RelationDefinition):
       
   228     subject = ('Card', 'Note', 'Personne')
       
   229     object = 'CWPermission'
       
   230 
       
   231 class require_state(RelationDefinition):
       
   232     subject = 'CWPermission'
       
   233     object = 'State'
       
   234 
       
   235 class personne_composite(RelationDefinition):
       
   236     subject='Personne'
       
   237     object='Personne'
       
   238     composite='subject'
       
   239 
       
   240 class personne_inlined(RelationDefinition):
       
   241     subject='Personne'
       
   242     object='Personne'
       
   243     cardinality='?*'
       
   244     inlined=True
       
   245 
       
   246 
       
   247 class login_user(RelationDefinition):
       
   248     subject = 'Personne'
       
   249     object = 'CWUser'
       
   250     cardinality = '??'
       
   251 
       
   252 class ambiguous_inlined(RelationDefinition):
       
   253     subject = ('Affaire', 'Note')
       
   254     object = 'CWUser'
       
   255     inlined = True
       
   256     cardinality = '?*'