schema.py
branchstable
changeset 5030 5238d9a8dfee
parent 4913 083b4d454192
child 5122 c06078d59e87
equal deleted inserted replaced
5029:f7709d28fb79 5030:5238d9a8dfee
    19 from logilab.common.graph import get_cycles
    19 from logilab.common.graph import get_cycles
    20 from logilab.common.compat import any
    20 from logilab.common.compat import any
    21 
    21 
    22 from yams import BadSchemaDefinition, buildobjs as ybo
    22 from yams import BadSchemaDefinition, buildobjs as ybo
    23 from yams.schema import Schema, ERSchema, EntitySchema, RelationSchema, \
    23 from yams.schema import Schema, ERSchema, EntitySchema, RelationSchema, \
    24      RelationDefinitionSchema, PermissionMixIn
    24      RelationDefinitionSchema, PermissionMixIn, role_name
    25 from yams.constraints import BaseConstraint, FormatConstraint
    25 from yams.constraints import BaseConstraint, FormatConstraint
    26 from yams.reader import (CONSTRAINTS, PyFileReader, SchemaLoader,
    26 from yams.reader import (CONSTRAINTS, PyFileReader, SchemaLoader,
    27                          obsolete as yobsolete, cleanup_sys_modules)
    27                          obsolete as yobsolete, cleanup_sys_modules)
    28 
    28 
    29 from rql import parse, nodes, RQLSyntaxError, TypeResolverException
    29 from rql import parse, nodes, RQLSyntaxError, TypeResolverException
   680         """
   680         """
   681         if not self.match_condition(session, eidfrom, eidto):
   681         if not self.match_condition(session, eidfrom, eidto):
   682             # XXX at this point if both or neither of S and O are in mainvar we
   682             # XXX at this point if both or neither of S and O are in mainvar we
   683             # dunno if the validation error `occured` on eidfrom or eidto (from
   683             # dunno if the validation error `occured` on eidfrom or eidto (from
   684             # user interface point of view)
   684             # user interface point of view)
       
   685             #
       
   686             # possible enhancement: check entity being created, it's probably
       
   687             # the main eid unless this is a composite relation
   685             if eidto is None or 'S' in self.mainvars or not 'O' in self.mainvars:
   688             if eidto is None or 'S' in self.mainvars or not 'O' in self.mainvars:
   686                 maineid = eidfrom
   689                 maineid = eidfrom
       
   690                 qname = role_name(rtype, 'subject')
   687             else:
   691             else:
   688                 maineid = eidto
   692                 maineid = eidto
       
   693                 qname = role_name(rtype, 'object')
   689             if self.msg:
   694             if self.msg:
   690                 msg = session._(self.msg)
   695                 msg = session._(self.msg)
   691             else:
   696             else:
   692                 msg = '%(constraint)s %(restriction)s failed' % {
   697                 msg = '%(constraint)s %(restriction)s failed' % {
   693                     'constraint':  session._(self.type()),
   698                     'constraint':  session._(self.type()),
   694                     'restriction': self.restriction}
   699                     'restriction': self.restriction}
   695             raise ValidationError(maineid, {rtype: msg})
   700             raise ValidationError(maineid, {qname: msg})
   696 
   701 
   697     def exec_query(self, session, eidfrom, eidto):
   702     def exec_query(self, session, eidfrom, eidto):
   698         if eidto is None:
   703         if eidto is None:
   699             # checking constraint for an attribute relation
   704             # checking constraint for an attribute relation
   700             restriction = 'S eid %(s)s, ' + self.restriction
   705             restriction = 'S eid %(s)s, ' + self.restriction