test/data/schema.py
changeset 11057 0b59724cb3f2
parent 11052 058bb3dc685f
child 11058 23eb30449fe5
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
     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, String, RichString, Bytes,
       
    20                             SubjectRelation, RelationDefinition)
       
    21 
       
    22 from cubicweb.schema import (WorkflowableEntityType,
       
    23                              RQLConstraint, RQLVocabularyConstraint)
       
    24 
       
    25 
       
    26 from cubicweb import _
       
    27 
       
    28 
       
    29 class Personne(EntityType):
       
    30     nom = String(required=True)
       
    31     prenom = String()
       
    32     type = String()
       
    33     travaille = SubjectRelation('Societe')
       
    34     evaluee = SubjectRelation(('Note', 'Personne'))
       
    35     connait = SubjectRelation(
       
    36         'Personne', symmetric=True,
       
    37         constraints=[
       
    38             RQLConstraint('NOT S identity O'),
       
    39             # conflicting constraints, see cw_unrelated_rql tests in
       
    40             # unittest_entity.py
       
    41             RQLVocabularyConstraint('NOT (S connait P, P nom "toto")'),
       
    42             RQLVocabularyConstraint('S travaille P, P nom "tutu"')])
       
    43     actionnaire = SubjectRelation('Societe', cardinality='??',
       
    44                                   constraints=[RQLConstraint('NOT EXISTS(O contrat_exclusif S)')])
       
    45     dirige = SubjectRelation('Societe', cardinality='??',
       
    46                              constraints=[RQLConstraint('S actionnaire O')])
       
    47     associe = SubjectRelation('Personne', cardinality='?*',
       
    48                               constraints=[RQLConstraint('S actionnaire SOC, O actionnaire SOC')])
       
    49 
       
    50 class Ami(EntityType):
       
    51     """A Person, for which surname is not required"""
       
    52     prenom = String()
       
    53     nom = String()
       
    54 
       
    55 class Societe(EntityType):
       
    56     nom = String()
       
    57     evaluee = SubjectRelation('Note')
       
    58     fournit = SubjectRelation(('Service', 'Produit'), cardinality='1*')
       
    59     contrat_exclusif = SubjectRelation('Personne', cardinality='??')
       
    60 
       
    61 class Service(EntityType):
       
    62     fabrique_par = SubjectRelation('Personne', cardinality='1*')
       
    63 
       
    64 
       
    65 class Produit(EntityType):
       
    66     fabrique_par = SubjectRelation('Usine', cardinality='1*', inlined=True)
       
    67 
       
    68 
       
    69 class Usine(EntityType):
       
    70     lieu = String(required=True)
       
    71 
       
    72 
       
    73 class Note(EntityType):
       
    74     type = String()
       
    75     ecrit_par = SubjectRelation('Personne')
       
    76 
       
    77 
       
    78 class SubNote(Note):
       
    79     __specializes_schema__ = True
       
    80     description = String()
       
    81 
       
    82 
       
    83 class tags(RelationDefinition):
       
    84     subject = 'Tag'
       
    85     object = ('Personne', 'Note')
       
    86 
       
    87 
       
    88 class evaluee(RelationDefinition):
       
    89     subject = 'CWUser'
       
    90     object = 'Note'
       
    91 
       
    92 
       
    93 class StateFull(WorkflowableEntityType):
       
    94     name = String()
       
    95 
       
    96 
       
    97 class Reference(EntityType):
       
    98     nom = String(unique=True)
       
    99     ean = String(unique=True, required=True)
       
   100 
       
   101 
       
   102 class FakeFile(EntityType):
       
   103     title = String(fulltextindexed=True, maxsize=256)
       
   104     data = Bytes(required=True, fulltextindexed=True, description=_('file to upload'))
       
   105     data_format = String(required=True, maxsize=128,
       
   106                          description=_('MIME type of the file. Should be dynamically set at upload time.'))
       
   107     data_encoding = String(maxsize=32,
       
   108                            description=_('encoding of the file when it applies (e.g. text). '
       
   109                                          'Should be dynamically set at upload time.'))
       
   110     data_name = String(required=True, fulltextindexed=True,
       
   111                        description=_('name of the file. Should be dynamically set at upload time.'))
       
   112     description = RichString(fulltextindexed=True, internationalizable=True,
       
   113                              default_format='text/rest')