schema.py
changeset 2301 a9e9582d5fb6
parent 2300 c8151d004e06
child 2374 ea1a44e4ad62
equal deleted inserted replaced
2300:c8151d004e06 2301:a9e9582d5fb6
    18 from logilab.common.compat import any
    18 from logilab.common.compat import any
    19 
    19 
    20 from yams import BadSchemaDefinition, buildobjs as ybo
    20 from yams import BadSchemaDefinition, buildobjs as ybo
    21 from yams.schema import Schema, ERSchema, EntitySchema, RelationSchema
    21 from yams.schema import Schema, ERSchema, EntitySchema, RelationSchema
    22 from yams.constraints import BaseConstraint, StaticVocabularyConstraint
    22 from yams.constraints import BaseConstraint, StaticVocabularyConstraint
    23 from yams.reader import CONSTRAINTS, PyFileReader, SchemaLoader
    23 from yams.reader import CONSTRAINTS, PyFileReader, SchemaLoader, \
       
    24      obsolete as yobsolete
    24 
    25 
    25 from rql import parse, nodes, RQLSyntaxError, TypeResolverException
    26 from rql import parse, nodes, RQLSyntaxError, TypeResolverException
    26 
    27 
    27 from cubicweb import ETYPE_NAME_MAP, ValidationError, Unauthorized
    28 from cubicweb import ETYPE_NAME_MAP, ValidationError, Unauthorized
    28 from cubicweb import set_log_methods
    29 from cubicweb import set_log_methods
    83     def __init__(self, default_format='text/plain', format_constraints=None, **kwargs):
    84     def __init__(self, default_format='text/plain', format_constraints=None, **kwargs):
    84         self.default_format = default_format
    85         self.default_format = default_format
    85         self.format_constraints = format_constraints or [format_constraint]
    86         self.format_constraints = format_constraints or [format_constraint]
    86         super(RichString, self).__init__(**kwargs)
    87         super(RichString, self).__init__(**kwargs)
    87 
    88 
    88 PyFileReader.context['RichString'] = RichString
    89 PyFileReader.context['RichString'] = yobsolete(RichString)
    89 
    90 
    90 ## need to monkeypatch yams' _add_relation function to handle RichString
    91 ## need to monkeypatch yams' _add_relation function to handle RichString
    91 yams_add_relation = ybo._add_relation
    92 yams_add_relation = ybo._add_relation
    92 @monkeypatch(ybo)
    93 @monkeypatch(ybo)
    93 def _add_relation(relations, rdef, name=None, insertidx=None):
    94 def _add_relation(relations, rdef, name=None, insertidx=None):
   790             if eid is None:
   791             if eid is None:
   791                 return False
   792                 return False
   792             return self._check(session, x=eid)
   793             return self._check(session, x=eid)
   793         return self._check(session)
   794         return self._check(session)
   794 
   795 
   795 PyFileReader.context['ERQLExpression'] = ERQLExpression
   796 PyFileReader.context['ERQLExpression'] = yobsolete(ERQLExpression)
   796 
   797 
   797 class RRQLExpression(RQLExpression):
   798 class RRQLExpression(RQLExpression):
   798     def __init__(self, expression, mainvars=None, eid=None):
   799     def __init__(self, expression, mainvars=None, eid=None):
   799         if mainvars is None:
   800         if mainvars is None:
   800             defined = set(split_expression(expression))
   801             defined = set(split_expression(expression))
   834             if toeid is None:
   835             if toeid is None:
   835                 return False
   836                 return False
   836             kwargs['o'] = toeid
   837             kwargs['o'] = toeid
   837         return self._check(session, **kwargs)
   838         return self._check(session, **kwargs)
   838 
   839 
   839 PyFileReader.context['RRQLExpression'] = RRQLExpression
   840 PyFileReader.context['RRQLExpression'] = yobsolete(RRQLExpression)
   840 
   841 
   841 # workflow extensions #########################################################
   842 # workflow extensions #########################################################
   842 
   843 
   843 class workflowable_definition(ybo.metadefinition):
   844 class workflowable_definition(ybo.metadefinition):
   844     """extends default EntityType's metaclass to add workflow relations
   845     """extends default EntityType's metaclass to add workflow relations