schemas/base.py
changeset 6427 c8a5ac2d1eaa
parent 5896 67683b7e591a
child 6622 27402fe6a94a
equal deleted inserted replaced
6426:541659c39f6a 6427:c8a5ac2d1eaa
    18 """core CubicWeb schema, but not necessary at bootstrap time"""
    18 """core CubicWeb schema, but not necessary at bootstrap time"""
    19 
    19 
    20 __docformat__ = "restructuredtext en"
    20 __docformat__ = "restructuredtext en"
    21 _ = unicode
    21 _ = unicode
    22 
    22 
    23 from yams.buildobjs import (EntityType, RelationType, SubjectRelation,
    23 from yams.buildobjs import (EntityType, RelationType, RelationDefinition,
    24                             String, Datetime, Password)
    24                             SubjectRelation, String, Datetime, Password)
    25 from cubicweb.schema import (
    25 from cubicweb.schema import (
    26     RQLConstraint, WorkflowableEntityType, ERQLExpression, RRQLExpression,
    26     RQLConstraint, WorkflowableEntityType, ERQLExpression, RRQLExpression,
    27     PUB_SYSTEM_ENTITY_PERMS, PUB_SYSTEM_REL_PERMS, PUB_SYSTEM_ATTR_PERMS)
    27     PUB_SYSTEM_ENTITY_PERMS, PUB_SYSTEM_REL_PERMS, PUB_SYSTEM_ATTR_PERMS)
    28 
    28 
    29 class CWUser(WorkflowableEntityType):
    29 class CWUser(WorkflowableEntityType):
    60         'delete': ('managers', 'owners', ERQLExpression('P use_email X, U has_update_permission P')),
    60         'delete': ('managers', 'owners', ERQLExpression('P use_email X, U has_update_permission P')),
    61         'update': ('managers', 'owners', ERQLExpression('P use_email X, U has_update_permission P')),
    61         'update': ('managers', 'owners', ERQLExpression('P use_email X, U has_update_permission P')),
    62         }
    62         }
    63 
    63 
    64     alias   = String(fulltextindexed=True, maxsize=56)
    64     alias   = String(fulltextindexed=True, maxsize=56)
    65     address = String(required=True, fulltextindexed=True,
    65     address = String(required=True,  fulltextindexed=True,
    66                      indexed=True, unique=True, maxsize=128)
    66                      indexed=True, unique=True, maxsize=128)
    67     prefered_form = SubjectRelation('EmailAddress', cardinality='?*',
    67     prefered_form = SubjectRelation('EmailAddress', cardinality='?*',
    68                                     description=_('when multiple addresses are equivalent \
    68                                     description=_('when multiple addresses are equivalent \
    69 (such as python-projects@logilab.org and python-projects@lists.logilab.org), set this \
    69 (such as python-projects@logilab.org and python-projects@lists.logilab.org), set this \
    70 to indicate which is the preferred form.'))
    70 to indicate which is the preferred form.'))
   196 class ExternalUri(EntityType):
   196 class ExternalUri(EntityType):
   197     """a URI representing an object in external data store"""
   197     """a URI representing an object in external data store"""
   198     uri = String(required=True, unique=True, maxsize=256,
   198     uri = String(required=True, unique=True, maxsize=256,
   199                  description=_('the URI of the object'))
   199                  description=_('the URI of the object'))
   200 
   200 
       
   201 
   201 class same_as(RelationType):
   202 class same_as(RelationType):
   202     """generic relation to specify that an external entity represent the same
   203     """generic relation to specify that an external entity represent the same
   203     object as a local one:
   204     object as a local one:
   204        http://www.w3.org/TR/owl-ref/#sameAs-def
   205        http://www.w3.org/TR/owl-ref/#sameAs-def
   205     """
   206     """
   214     symmetric = True
   215     symmetric = True
   215     # NOTE: the 'object = ExternalUri' declaration will still be mandatory
   216     # NOTE: the 'object = ExternalUri' declaration will still be mandatory
   216     #       in the cube's schema.
   217     #       in the cube's schema.
   217     object = 'ExternalUri'
   218     object = 'ExternalUri'
   218 
   219 
       
   220 
   219 class CWCache(EntityType):
   221 class CWCache(EntityType):
   220     """a simple cache entity characterized by a name and
   222     """a simple cache entity characterized by a name and
   221     a validity date.
   223     a validity date.
   222 
   224 
   223     The target application is responsible for updating timestamp
   225     The target application is responsible for updating timestamp
   232         'add':    ('managers',),
   234         'add':    ('managers',),
   233         'update': ('managers', 'users',), # XXX
   235         'update': ('managers', 'users',), # XXX
   234         'delete': ('managers',),
   236         'delete': ('managers',),
   235         }
   237         }
   236 
   238 
   237     name = String(required=True, unique=True, indexed=True,  maxsize=128,
   239     name = String(required=True, unique=True, maxsize=128,
   238                   description=_('name of the cache'))
   240                   description=_('name of the cache'))
   239     timestamp = Datetime(default='NOW')
   241     timestamp = Datetime(default='NOW')
   240 
   242 
   241 
   243 
   242 # "abtract" relation types, not used in cubicweb itself
   244 class CWSource(EntityType):
       
   245     name = String(required=True, unique=True, maxsize=128,
       
   246                   description=_('name of the source'))
       
   247     type = String(required=True, maxsize=20, description=_('type of the source'))
       
   248     config = String(description=_('source\'s configuration. One key=value per '
       
   249                                   'line, authorized keys depending on the '
       
   250                                   'source\'s type'),
       
   251                     __permissions__={
       
   252                         'read':   ('managers',),
       
   253                         'update': ('managers',),
       
   254                         })
       
   255 
       
   256 
       
   257 class CWSourceHostConfig(EntityType):
       
   258     __permissions__ = {
       
   259         'read':   ('managers',),
       
   260         'add':    ('managers',),
       
   261         'update': ('managers',),
       
   262         'delete': ('managers',),
       
   263         }
       
   264     match_host = String(required=True, unique=True, maxsize=128,
       
   265                         description=_('regexp matching host(s) to which this config applies'))
       
   266     config = String(required=True,
       
   267                     description=_('Source\'s configuration for a particular host. '
       
   268                                   'One key=value per line, authorized keys '
       
   269                                   'depending on the source\'s type, overriding '
       
   270                                   'values defined on the source.'),
       
   271                     __permissions__={
       
   272                         'read':   ('managers',),
       
   273                         'update': ('managers',),
       
   274                         })
       
   275 
       
   276 
       
   277 class cw_host_config_of(RelationDefinition):
       
   278     subject = 'CWSourceHostConfig'
       
   279     object = 'CWSource'
       
   280     cardinality = '1*'
       
   281     composite = 'object'
       
   282     inlined = True
       
   283 
       
   284 class cw_source(RelationDefinition):
       
   285     __permissions__ = {
       
   286         'read':   ('managers', 'users', 'guests'),
       
   287         'add':    (),
       
   288         'delete': (),
       
   289         }
       
   290     subject = '*'
       
   291     object = 'CWSource'
       
   292     cardinality = '1*'
       
   293 
       
   294 class cw_support(RelationDefinition):
       
   295     subject = 'CWSource'
       
   296     object = ('CWEType', 'CWRType')
       
   297 
       
   298 class cw_dont_cross(RelationDefinition):
       
   299     subject = 'CWSource'
       
   300     object = 'CWRType'
       
   301 
       
   302 class cw_may_cross(RelationDefinition):
       
   303     subject = 'CWSource'
       
   304     object = 'CWRType'
       
   305 
       
   306 # "abtract" relation types, no definition in cubicweb itself ###################
   243 
   307 
   244 class identical_to(RelationType):
   308 class identical_to(RelationType):
   245     """identical to"""
   309     """identical to"""
   246     symmetric = True
   310     symmetric = True
   247     __permissions__ = {
   311     __permissions__ = {