equal
deleted
inserted
replaced
618 return int(self.target_etype in rschema.subjects(eschema)) |
618 return int(self.target_etype in rschema.subjects(eschema)) |
619 except KeyError, ex: |
619 except KeyError, ex: |
620 return 0 |
620 return 0 |
621 return 1 |
621 return 1 |
622 |
622 |
|
623 |
623 class partial_relation_possible(PartialSelectorMixIn, relation_possible): |
624 class partial_relation_possible(PartialSelectorMixIn, relation_possible): |
624 """partial version of the relation_possible selector |
625 """partial version of the relation_possible selector |
625 |
626 |
626 The selector will look for class attributes to find its missing |
627 The selector will look for class attributes to find its missing |
627 information. The list of attributes required on the class |
628 information. The list of attributes required on the class |
691 return 0 |
692 return 0 |
692 elif not rschema.has_perm(entity.req, 'add', toeid=entity.eid): |
693 elif not rschema.has_perm(entity.req, 'add', toeid=entity.eid): |
693 return 0 |
694 return 0 |
694 return 1 |
695 return 1 |
695 |
696 |
|
697 |
696 class partial_may_add_relation(PartialSelectorMixIn, may_add_relation): |
698 class partial_may_add_relation(PartialSelectorMixIn, may_add_relation): |
697 """partial version of the may_add_relation selector |
699 """partial version of the may_add_relation selector |
698 |
700 |
699 The selector will look for class attributes to find its missing |
701 The selector will look for class attributes to find its missing |
700 information. The list of attributes required on the class |
702 information. The list of attributes required on the class |
718 |
720 |
719 |
721 |
720 class has_related_entities(EntitySelector): |
722 class has_related_entities(EntitySelector): |
721 """accept if entity found in the result set has some linked entities using |
723 """accept if entity found in the result set has some linked entities using |
722 the specified relation (optionaly filtered according to the specified target |
724 the specified relation (optionaly filtered according to the specified target |
723 type). |
725 type). Checks first if the relation is possible. |
724 |
726 |
725 See `EntitySelector` documentation for behaviour when row is not specified. |
727 See `EntitySelector` documentation for behaviour when row is not specified. |
726 |
728 |
727 :param rtype: a relation type (`basestring`) |
729 :param rtype: a relation type (`basestring`) |
728 :param role: the role of the result set entity in the relation. 'subject' or |
730 :param role: the role of the result set entity in the relation. 'subject' or |
736 self.rtype = rtype |
738 self.rtype = rtype |
737 self.role = role |
739 self.role = role |
738 self.target_etype = target_etype |
740 self.target_etype = target_etype |
739 |
741 |
740 def score_entity(self, entity): |
742 def score_entity(self, entity): |
|
743 relpossel = relation_possible(self.rtype, self.role, self.target_etype) |
|
744 if not relpossel.score_class(entity.__class__, entity.req): |
|
745 return 0 |
741 rset = entity.related(self.rtype, self.role) |
746 rset = entity.related(self.rtype, self.role) |
742 if self.target_etype: |
747 if self.target_etype: |
743 return any(x for x, in rset.description if x == self.target_etype) |
748 return any(x for x, in rset.description if x == self.target_etype) |
744 return rset and 1 or 0 |
749 return rset and 1 or 0 |
745 |
750 |
819 continue |
824 continue |
820 if not self.score(req, rset, i, col): |
825 if not self.score(req, rset, i, col): |
821 return 0 |
826 return 0 |
822 score += 1 |
827 score += 1 |
823 return score |
828 return score |
824 return self.score(req, rset, i, col) |
829 return self.score(req, rset, row, col) |
825 |
830 |
826 def score_entity(self, entity): |
831 def score_entity(self, entity): |
827 if entity.has_perm(self.action): |
832 if entity.has_perm(self.action): |
828 return 1 |
833 return 1 |
829 return 0 |
834 return 0 |