common/selectors.py
changeset 266 b36670d730b2
parent 254 b1eda3dd844a
child 333 c65eccf85895
equal deleted inserted replaced
265:97361ddaf342 266:b36670d730b2
   356     .rtype attribute of the class, and if all entities types in the
   356     .rtype attribute of the class, and if all entities types in the
   357     result set has this relation.
   357     result set has this relation.
   358     """
   358     """
   359     if hasattr(cls, 'rtype'):
   359     if hasattr(cls, 'rtype'):
   360         perm = getattr(cls, 'require_permission', 'read')
   360         perm = getattr(cls, 'require_permission', 'read')
   361         if not schema.rschema(cls.rtype).has_perm(req, perm):
   361         if not cls.schema.rschema(cls.rtype).has_perm(req, perm):
   362             return 0
   362             return 0
   363         if row is None:
   363         if row is None:
   364             for etype in rset.column_types(col or 0):
   364             for etype in rset.column_types(col or 0):
   365                 if not cls.relation_possible(etype):
   365                 if not cls.relation_possible(etype):
   366                     return 0
   366                     return 0
   373 def one_has_relation(cls, req, rset, row=None, col=None, **kwargs):
   373 def one_has_relation(cls, req, rset, row=None, col=None, **kwargs):
   374     """check if the user has read access on the relations's type refered by the
   374     """check if the user has read access on the relations's type refered by the
   375     .rtype attribute of the class, and if at least one entity type in the
   375     .rtype attribute of the class, and if at least one entity type in the
   376     result set has this relation.
   376     result set has this relation.
   377     """
   377     """
   378     schema = cls.schema
       
   379     perm = getattr(cls, 'require_permission', 'read')
   378     perm = getattr(cls, 'require_permission', 'read')
   380     if not schema.rschema(cls.rtype).has_perm(req, perm):
   379     if not cls.schema.rschema(cls.rtype).has_perm(req, perm):
   381         return 0
   380         return 0
   382     if row is None:
   381     if row is None:
   383         for etype in rset.column_types(col or 0):
   382         for etype in rset.column_types(col or 0):
   384             if cls.relation_possible(etype):
   383             if cls.relation_possible(etype):
   385                 return 1
   384                 return 1