# HG changeset patch # User Sylvain Thénault # Date 1263400902 -3600 # Node ID 0adf456974229d3e0c3fe965c491db8aef8ad884 # Parent 94ffaecd8e8c4c12d939b11f684cdc811ccd3b40 if specified, benefit from target_etype information in the [partial_]add_relation selector diff -r 94ffaecd8e8c -r 0adf45697422 selectors.py --- a/selectors.py Wed Jan 13 17:40:53 2010 +0100 +++ b/selectors.py Wed Jan 13 17:41:42 2010 +0100 @@ -718,13 +718,17 @@ 'object', default to 'subject'. """ - def __init__(self, rtype, role='subject', once_is_enough=False): + def __init__(self, rtype, role='subject', target_etype=None, + once_is_enough=False): super(may_add_relation, self).__init__(once_is_enough) self.rtype = rtype self.role = role + self.target_etype = target_etype def score_entity(self, entity): rschema = entity.schema.rschema(self.rtype) + if self.target_etype is not None: + rschema = rschema.role_rdef(entity.e_schema, self.target_etype, self.role) if self.role == 'subject': if not rschema.has_perm(entity._cw, 'add', fromeid=entity.eid): return 0 @@ -750,11 +754,12 @@ be returned """ def __init__(self, once_is_enough=False): - super(partial_may_add_relation, self).__init__(None, None, once_is_enough) + super(partial_may_add_relation, self).__init__(None, once_is_enough=once_is_enough) def complete(self, cls): self.rtype = cls.rtype self.role = role(cls) + self.target_etype = getattr(cls, 'etype', None) class has_related_entities(EntitySelector):