server/test/data/schema.py
changeset 11057 0b59724cb3f2
parent 11052 058bb3dc685f
child 11058 23eb30449fe5
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
     1 # copyright 2003-2014 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, ComputedRelation,
       
    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                              RQLVocabularyConstraint,
       
    26                              ERQLExpression, RRQLExpression)
       
    27 from cubicweb import _
       
    28 
       
    29 class Affaire(WorkflowableEntityType):
       
    30     __permissions__ = {
       
    31         'read':   ('managers',
       
    32                    ERQLExpression('X owned_by U'), ERQLExpression('X concerne S?, S owned_by U')),
       
    33         'add':    ('managers', ERQLExpression('X concerne S, S owned_by U')),
       
    34         'update': ('managers', 'owners', ERQLExpression('X in_state S, S name in ("pitetre", "en cours")')),
       
    35         'delete': ('managers', 'owners', ERQLExpression('X concerne S, S owned_by U')),
       
    36         }
       
    37 
       
    38     ref = String(fulltextindexed=True, indexed=True,
       
    39                  constraints=[SizeConstraint(16)])
       
    40     sujet = String(fulltextindexed=True,
       
    41                    constraints=[SizeConstraint(256)])
       
    42     descr = RichString(fulltextindexed=True,
       
    43                        description=_('more detailed description'))
       
    44 
       
    45     duration = Int()
       
    46     invoiced = Float()
       
    47     opt_attr = Bytes()
       
    48 
       
    49     depends_on = SubjectRelation('Affaire')
       
    50     require_permission = SubjectRelation('CWPermission')
       
    51     concerne = SubjectRelation(('Societe', 'Note'))
       
    52     todo_by = SubjectRelation('Personne', cardinality='?*')
       
    53     documented_by = SubjectRelation('Card')
       
    54 
       
    55 
       
    56 class Societe(EntityType):
       
    57     __unique_together__ = [('nom', 'type', 'cp')]
       
    58     __permissions__ = {
       
    59         'read': ('managers', 'users', 'guests'),
       
    60         'update': ('managers', 'owners', ERQLExpression('U login L, X nom L')),
       
    61         'delete': ('managers', 'owners', ERQLExpression('U login L, X nom L')),
       
    62         'add': ('managers', 'users',)
       
    63         }
       
    64 
       
    65     nom  = String(maxsize=64, fulltextindexed=True)
       
    66     web  = String(maxsize=128)
       
    67     type  = String(maxsize=128) # attribute in common with Note
       
    68     tel  = Int()
       
    69     fax  = Int()
       
    70     rncs = String(maxsize=128)
       
    71     ad1  = String(maxsize=128)
       
    72     ad2  = String(maxsize=128)
       
    73     ad3  = String(maxsize=128)
       
    74     cp   = String(maxsize=12)
       
    75     ville= String(maxsize=32)
       
    76 
       
    77 
       
    78 class Division(Societe):
       
    79     __specializes_schema__ = True
       
    80 
       
    81 class SubDivision(Division):
       
    82     __specializes_schema__ = True
       
    83 
       
    84 class travaille_subdivision(RelationDefinition):
       
    85     subject = 'Personne'
       
    86     object = 'SubDivision'
       
    87 
       
    88 from cubicweb.schemas.base import CWUser
       
    89 next(CWUser.get_relations('login')).fulltextindexed = True
       
    90 
       
    91 class Note(WorkflowableEntityType):
       
    92     date = String(maxsize=10)
       
    93     type = String(vocabulary=[u'todo', u'a', u'b', u'T', u'lalala'])
       
    94     para = String(maxsize=512,
       
    95                   __permissions__ = {
       
    96                       'add': ('managers', ERQLExpression('X in_state S, S name "todo"')),
       
    97                       'read':   ('managers', 'users', 'guests'),
       
    98                       'update': ('managers', ERQLExpression('X in_state S, S name "todo"')),
       
    99                       })
       
   100     something = String(maxsize=1,
       
   101                       __permissions__ = {
       
   102                           'read': ('managers', 'users', 'guests'),
       
   103                           'add': (ERQLExpression('NOT X para NULL'),),
       
   104                           'update': ('managers', 'owners')
       
   105                       })
       
   106     migrated_from = SubjectRelation('Note')
       
   107     attachment = SubjectRelation('File')
       
   108     inline1 = SubjectRelation('Affaire', inlined=True, cardinality='?*',
       
   109                               constraints=[RQLUniqueConstraint('S type T, S inline1 A1, A1 todo_by C, '
       
   110                                                               'Y type T, Y inline1 A2, A2 todo_by C',
       
   111                                                                'S,Y')])
       
   112     todo_by = SubjectRelation('CWUser')
       
   113 
       
   114 
       
   115 class Frozable(EntityType):
       
   116     __permissions__ = {
       
   117         'read':   ('managers', 'users'),
       
   118         'add':    ('managers', 'users'),
       
   119         'update': ('managers', ERQLExpression('X frozen False'),),
       
   120         'delete': ('managers', ERQLExpression('X frozen False'),)
       
   121     }
       
   122     name = String()
       
   123     frozen = Boolean(default=False,
       
   124                      __permissions__ = {
       
   125                          'read':   ('managers', 'users'),
       
   126                          'add':    ('managers', 'users'),
       
   127                          'update': ('managers', 'owners')
       
   128                          })
       
   129 
       
   130 
       
   131 class Personne(EntityType):
       
   132     __permissions__ = {
       
   133         'read':   ('managers', 'users', 'guests'), # 'guests' will be removed
       
   134         'add':    ('managers', 'users'),
       
   135         'update': ('managers', 'owners'),
       
   136         'delete': ('managers', 'owners')
       
   137     }
       
   138     __unique_together__ = [('nom', 'prenom', 'inline2')]
       
   139     nom    = String(fulltextindexed=True, required=True, maxsize=64)
       
   140     prenom = String(fulltextindexed=True, maxsize=64)
       
   141     sexe   = String(maxsize=1, default='M', fulltextindexed=True)
       
   142     promo  = String(vocabulary=('bon','pasbon'))
       
   143     titre  = String(fulltextindexed=True, maxsize=128)
       
   144     adel   = String(maxsize=128)
       
   145     ass    = String(maxsize=128)
       
   146     web    = String(maxsize=128)
       
   147     tel    = Int()
       
   148     fax    = Int()
       
   149     datenaiss = Datetime()
       
   150     tzdatenaiss = TZDatetime()
       
   151     test   = Boolean(__permissions__={
       
   152         'read': ('managers', 'users', 'guests'),
       
   153         'add': ('managers',),
       
   154         'update': ('managers',),
       
   155         })
       
   156     description = String()
       
   157     firstname = String(fulltextindexed=True, maxsize=64)
       
   158 
       
   159     concerne = SubjectRelation('Affaire')
       
   160     connait = SubjectRelation('Personne')
       
   161     inline2 = SubjectRelation('Affaire', inlined=True, cardinality='?*')
       
   162 
       
   163 
       
   164 class Old(EntityType):
       
   165     name = String(__permissions__ = {
       
   166         'read'   : ('managers', 'users', 'guests'),
       
   167         'add'    : ('managers', 'users', 'guests'),
       
   168         'update' : ()
       
   169     })
       
   170 
       
   171 
       
   172 class Email(EntityType):
       
   173     subject = String(fulltextindexed=True)
       
   174     messageid = String(required=True, indexed=True, unique=True)
       
   175     sender = SubjectRelation('EmailAddress', cardinality='?*')
       
   176     recipients = SubjectRelation('EmailAddress')
       
   177     attachment = SubjectRelation('File')
       
   178 
       
   179 
       
   180 class EmailPart(EntityType):
       
   181     pass
       
   182 
       
   183 
       
   184 class EmailThread(EntityType):
       
   185     see_also = SubjectRelation('EmailThread')
       
   186 
       
   187 
       
   188 class connait(RelationType):
       
   189     symmetric = True
       
   190 
       
   191 class concerne(RelationType):
       
   192     __permissions__ = {
       
   193         'read':   ('managers', 'users', 'guests'),
       
   194         'add':    ('managers', RRQLExpression('U has_update_permission S')),
       
   195         'delete': ('managers', RRQLExpression('O owned_by U')),
       
   196         }
       
   197 
       
   198 class travaille(RelationDefinition):
       
   199     __permissions__ = {
       
   200         'read':   ('managers', 'users', 'guests'),
       
   201         'add':    ('managers', RRQLExpression('U has_update_permission S')),
       
   202         'delete': ('managers', RRQLExpression('O owned_by U')),
       
   203         }
       
   204     subject = 'Personne'
       
   205     object = 'Societe'
       
   206     constraints = [RQLVocabularyConstraint('S owned_by U'),
       
   207                    RQLVocabularyConstraint('S created_by U')]
       
   208 
       
   209 class comments(RelationDefinition):
       
   210     subject = 'Comment'
       
   211     object = 'Personne'
       
   212 
       
   213 class fiche(RelationDefinition):
       
   214     inlined = True
       
   215     subject = 'Personne'
       
   216     object = 'Card'
       
   217     cardinality = '??'
       
   218 
       
   219 class multisource_inlined_rel(RelationDefinition):
       
   220     inlined = True
       
   221     cardinality = '?*'
       
   222     subject = ('Card', 'Note')
       
   223     object = ('Affaire', 'Note')
       
   224 
       
   225 
       
   226 class see_also_1(RelationDefinition):
       
   227     name = 'see_also'
       
   228     subject = object = 'Folder'
       
   229 
       
   230 class see_also_2(RelationDefinition):
       
   231     name = 'see_also'
       
   232     subject = ('Bookmark', 'Note')
       
   233     object = ('Bookmark', 'Note')
       
   234 
       
   235 class evaluee(RelationDefinition):
       
   236     subject = ('Personne', 'CWUser', 'Societe')
       
   237     object = ('Note')
       
   238     constraints = [
       
   239         RQLVocabularyConstraint('S created_by U'),
       
   240         RQLVocabularyConstraint('S owned_by U'),
       
   241     ]
       
   242 
       
   243 class ecrit_par(RelationType):
       
   244     inlined = True
       
   245 
       
   246 class ecrit_par_1(RelationDefinition):
       
   247     name = 'ecrit_par'
       
   248     subject = 'Note'
       
   249     object ='Personne'
       
   250     cardinality = '?*'
       
   251 
       
   252 class ecrit_par_2(RelationDefinition):
       
   253     name = 'ecrit_par'
       
   254     subject = 'Note'
       
   255     object ='CWUser'
       
   256     cardinality='?*'
       
   257 
       
   258 
       
   259 class copain(RelationDefinition):
       
   260     subject = object = 'CWUser'
       
   261 
       
   262 class tags(RelationDefinition):
       
   263     subject = 'Tag'
       
   264     object = ('CWUser', 'CWGroup', 'State', 'Note', 'Card', 'Affaire')
       
   265 
       
   266 class Folder(EntityType):
       
   267     """folders are used to classify entities. They may be defined as a tree.
       
   268     """
       
   269     name = String(required=True, indexed=True, internationalizable=True,
       
   270                   maxsize=64)
       
   271     description = RichString(fulltextindexed=True)
       
   272     filed_under = SubjectRelation('Folder', description=_('parent folder'))
       
   273 
       
   274 class filed_under(RelationDefinition):
       
   275     subject = ('Note', 'Affaire')
       
   276     object = 'Folder'
       
   277 
       
   278 class require_permission(RelationDefinition):
       
   279     subject = ('Card', 'Note', 'Personne')
       
   280     object = 'CWPermission'
       
   281 
       
   282 class require_state(RelationDefinition):
       
   283     subject = 'CWPermission'
       
   284     object = 'State'
       
   285 
       
   286 class personne_composite(RelationDefinition):
       
   287     subject='Personne'
       
   288     object='Personne'
       
   289     composite='subject'
       
   290 
       
   291 class personne_inlined(RelationDefinition):
       
   292     subject='Personne'
       
   293     object='Personne'
       
   294     cardinality='?*'
       
   295     inlined=True
       
   296 
       
   297 
       
   298 class login_user(RelationDefinition):
       
   299     subject = 'Personne'
       
   300     object = 'CWUser'
       
   301     cardinality = '??'
       
   302 
       
   303 class ambiguous_inlined(RelationDefinition):
       
   304     subject = ('Affaire', 'Note')
       
   305     object = 'CWUser'
       
   306     inlined = True
       
   307     cardinality = '?*'
       
   308 
       
   309 
       
   310 class user_login(ComputedRelation):
       
   311     rule = 'O login_user S'