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