schema.py
branchstable
changeset 4717 535705688f4f
parent 4702 d9e51820d0c2
child 4754 6bf17f810975
equal deleted inserted replaced
4716:55b6a3262071 4717:535705688f4f
    13 from logging import getLogger
    13 from logging import getLogger
    14 from warnings import warn
    14 from warnings import warn
    15 
    15 
    16 from logilab.common.decorators import cached, clear_cache, monkeypatch
    16 from logilab.common.decorators import cached, clear_cache, monkeypatch
    17 from logilab.common.logging_ext import set_log_methods
    17 from logilab.common.logging_ext import set_log_methods
    18 from logilab.common.deprecation import deprecated
    18 from logilab.common.deprecation import deprecated, class_moved
    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
    25 from yams.constraints import (BaseConstraint, StaticVocabularyConstraint,
    25 from yams.constraints import BaseConstraint, FormatConstraint
    26                               FormatConstraint)
       
    27 from yams.reader import (CONSTRAINTS, PyFileReader, SchemaLoader,
    26 from yams.reader import (CONSTRAINTS, PyFileReader, SchemaLoader,
    28                          obsolete as yobsolete, cleanup_sys_modules)
    27                          obsolete as yobsolete, cleanup_sys_modules)
    29 
    28 
    30 from rql import parse, nodes, RQLSyntaxError, TypeResolverException
    29 from rql import parse, nodes, RQLSyntaxError, TypeResolverException
    31 
    30 
   764                 if objvar.name not in selected:
   763                 if objvar.name not in selected:
   765                     colindex = len(selected)
   764                     colindex = len(selected)
   766                     rqlst.add_selected(objvar)
   765                     rqlst.add_selected(objvar)
   767                 else:
   766                 else:
   768                     colindex = selected.index(objvar.name)
   767                     colindex = selected.index(objvar.name)
   769                 found.append((action, objvar, colindex))
   768                 found.append((action, colindex))
   770                 # remove U eid %(u)s if U is not used in any other relation
   769                 # remove U eid %(u)s if U is not used in any other relation
   771                 uvrefs = rqlst.defined_vars['U'].references()
   770                 uvrefs = rqlst.defined_vars['U'].references()
   772                 if len(uvrefs) == 1:
   771                 if len(uvrefs) == 1:
   773                     rqlst.remove_node(uvrefs[0].relation())
   772                     rqlst.remove_node(uvrefs[0].relation())
   774         if found is not None:
   773         if found is not None:
   832                 return True
   831                 return True
   833         elif rset:
   832         elif rset:
   834             # check every special has_*_permission relation is satisfied
   833             # check every special has_*_permission relation is satisfied
   835             get_eschema = session.vreg.schema.eschema
   834             get_eschema = session.vreg.schema.eschema
   836             try:
   835             try:
   837                 for eaction, var, col in has_perm_defs:
   836                 for eaction, col in has_perm_defs:
   838                     for i in xrange(len(rset)):
   837                     for i in xrange(len(rset)):
   839                         eschema = get_eschema(rset.description[i][col])
   838                         eschema = get_eschema(rset.description[i][col])
   840                         eschema.check_perm(session, eaction, eid=rset[i][col])
   839                         eschema.check_perm(session, eaction, eid=rset[i][col])
   841                 if self.eid is not None:
   840                 if self.eid is not None:
   842                     session.local_perm_cache[key] = True
   841                     session.local_perm_cache[key] = True
  1089 stmts.Select.set_statement_type = bw_set_statement_type
  1088 stmts.Select.set_statement_type = bw_set_statement_type
  1090 
  1089 
  1091 # XXX deprecated
  1090 # XXX deprecated
  1092 
  1091 
  1093 from yams.buildobjs import RichString
  1092 from yams.buildobjs import RichString
       
  1093 from yams.constraints import StaticVocabularyConstraint
       
  1094 
       
  1095 RichString = class_moved(RichString)
       
  1096 
       
  1097 StaticVocabularyConstraint = class_moved(StaticVocabularyConstraint)
       
  1098 FormatConstraint = class_moved(FormatConstraint)
  1094 
  1099 
  1095 PyFileReader.context['ERQLExpression'] = yobsolete(ERQLExpression)
  1100 PyFileReader.context['ERQLExpression'] = yobsolete(ERQLExpression)
  1096 PyFileReader.context['RRQLExpression'] = yobsolete(RRQLExpression)
  1101 PyFileReader.context['RRQLExpression'] = yobsolete(RRQLExpression)
  1097 PyFileReader.context['WorkflowableEntityType'] = WorkflowableEntityType
  1102 PyFileReader.context['WorkflowableEntityType'] = WorkflowableEntityType