cubicweb/server/test/data-schema2sql/schema/State.py
changeset 11057 0b59724cb3f2
parent 10790 117a6bbefbfd
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
       
     1 # copyright 2004-2013 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 yams.
       
     5 #
       
     6 # yams 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 # yams is distributed in the hope that it will be useful, but WITHOUT ANY
       
    12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
       
    13 # 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 yams. If not, see <http://www.gnu.org/licenses/>.
       
    18 from yams.buildobjs import (EntityType, RelationType, RelationDefinition,
       
    19                             SubjectRelation, Int, String,  Boolean)
       
    20 from yams.constraints import SizeConstraint, UniqueConstraint
       
    21 
       
    22 from . import RESTRICTED_RTYPE_PERMS
       
    23 
       
    24 class State(EntityType):
       
    25     """used to associate simple states to an entity
       
    26     type and/or to define workflows
       
    27     """
       
    28     __permissions__ = {
       
    29         'read':   ('managers', 'users', 'guests',),
       
    30         'add':    ('managers', 'users',),
       
    31         'delete': ('managers', 'owners',),
       
    32         'update': ('managers', 'owners',),
       
    33         }
       
    34 
       
    35     # attributes
       
    36     eid = Int(required=True, uid=True)
       
    37     name = String(required=True,
       
    38                   indexed=True, internationalizable=True,
       
    39                   constraints=[SizeConstraint(256)])
       
    40     description = String(fulltextindexed=True)
       
    41     # relations
       
    42     state_of = SubjectRelation('Eetype', cardinality='+*')
       
    43     next_state = SubjectRelation('State', cardinality='**')
       
    44 
       
    45 
       
    46 class state_of(RelationType):
       
    47     """link a state to one or more entity type"""
       
    48     __permissions__ = RESTRICTED_RTYPE_PERMS
       
    49 
       
    50 class next_state(RelationType):
       
    51     """define a workflow by associating a state to possible following states
       
    52     """
       
    53     __permissions__ = RESTRICTED_RTYPE_PERMS
       
    54 
       
    55 class initial_state(RelationType):
       
    56     """indicate which state should be used by default when an entity using states
       
    57     is created
       
    58     """
       
    59     __permissions__ = {
       
    60         'read':   ('managers', 'users', 'guests',),
       
    61         'add':    ('managers', 'users',),
       
    62         'delete': ('managers', 'users',),
       
    63         }
       
    64     subject = 'Eetype'
       
    65     object = 'State'
       
    66     cardinality = '?*'
       
    67     inlined = True
       
    68 
       
    69 class Eetype(EntityType):
       
    70     """define an entity type, used to build the application schema"""
       
    71     __permissions__ = {
       
    72         'read':   ('managers', 'users', 'guests',),
       
    73         'add':    ('managers',),
       
    74         'delete': ('managers',),
       
    75         'update': ('managers', 'owners',),
       
    76         }
       
    77     name = String(required=True, indexed=True, internationalizable=True,
       
    78                   constraints=[UniqueConstraint(), SizeConstraint(64)])
       
    79     description = String(fulltextindexed=True)
       
    80     meta = Boolean()
       
    81     final = Boolean()