selectors.py
changeset 3378 2f25f701301d
parent 3369 7b88d12b4ee2
child 3396 fb261afd49cd
equal deleted inserted replaced
3377:dd9d292b6a6d 3378:2f25f701301d
   635 
   635 
   636     note: when interface is an entity class, the score will reflect class
   636     note: when interface is an entity class, the score will reflect class
   637           proximity so the most specific object'll be selected
   637           proximity so the most specific object'll be selected
   638     """
   638     """
   639     def score_entity(self, entity):
   639     def score_entity(self, entity):
   640         return self.score_interfaces(entity.req, entity, entity.__class__)
   640         return self.score_interfaces(entity._cw, entity, entity.__class__)
   641 
   641 
   642 
   642 
   643 class relation_possible(EClassSelector):
   643 class relation_possible(EClassSelector):
   644     """accept if entity class found in the result set support the relation.
   644     """accept if entity class found in the result set support the relation.
   645 
   645 
   740         self.role = role
   740         self.role = role
   741 
   741 
   742     def score_entity(self, entity):
   742     def score_entity(self, entity):
   743         rschema = entity.schema.rschema(self.rtype)
   743         rschema = entity.schema.rschema(self.rtype)
   744         if self.role == 'subject':
   744         if self.role == 'subject':
   745             if not rschema.has_perm(entity.req, 'add', fromeid=entity.eid):
   745             if not rschema.has_perm(entity._cw, 'add', fromeid=entity.eid):
   746                 return 0
   746                 return 0
   747         elif not rschema.has_perm(entity.req, 'add', toeid=entity.eid):
   747         elif not rschema.has_perm(entity._cw, 'add', toeid=entity.eid):
   748             return 0
   748             return 0
   749         return 1
   749         return 1
   750 
   750 
   751 
   751 
   752 class partial_may_add_relation(PartialSelectorMixIn, may_add_relation):
   752 class partial_may_add_relation(PartialSelectorMixIn, may_add_relation):
   793         self.role = role
   793         self.role = role
   794         self.target_etype = target_etype
   794         self.target_etype = target_etype
   795 
   795 
   796     def score_entity(self, entity):
   796     def score_entity(self, entity):
   797         relpossel = relation_possible(self.rtype, self.role, self.target_etype)
   797         relpossel = relation_possible(self.rtype, self.role, self.target_etype)
   798         if not relpossel.score_class(entity.__class__, entity.req):
   798         if not relpossel.score_class(entity.__class__, entity._cw):
   799             return 0
   799             return 0
   800         rset = entity.related(self.rtype, self.role)
   800         rset = entity.related(self.rtype, self.role)
   801         if self.target_etype:
   801         if self.target_etype:
   802             return any(r for r in rset.description if r[0] == self.target_etype)
   802             return any(r for r in rset.description if r[0] == self.target_etype)
   803         return rset and 1 or 0
   803         return rset and 1 or 0