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