[facet] allow to specify a target type on relation facets for case such as Keyword/CodeKeyword where we only targets Keyword stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 24 Mar 2010 18:38:23 +0100
branchstable
changeset 5006 871269e5e020
parent 5005 b04ec1b6f7da
child 5007 bc0a67a95b69
[facet] allow to specify a target type on relation facets for case such as Keyword/CodeKeyword where we only targets Keyword
web/facet.py
--- a/web/facet.py	Wed Mar 24 18:38:19 2010 +0100
+++ b/web/facet.py	Wed Mar 24 18:38:23 2010 +0100
@@ -338,10 +338,11 @@
 
 class RelationFacet(VocabularyFacet):
     __select__ = partial_relation_possible() & match_context_prop()
-    # class attributes to configure the rel ation facet
+    # class attributes to configure the relation facet
     rtype = None
     role = 'subject'
     target_attr = 'eid'
+    target_type = None
     # set this to a stored procedure name if you want to sort on the result of
     # this function's result instead of direct value
     sortfunc = None
@@ -365,8 +366,11 @@
             sort = self.sortasc
         try:
             mainvar = self.filtered_variable
-            insert_attr_select_relation(rqlst, mainvar, self.rtype, self.role,
-                                        self.target_attr, self.sortfunc, sort)
+            var = insert_attr_select_relation(
+                rqlst, mainvar, self.rtype, self.role, self.target_attr,
+                self.sortfunc, sort)
+            if self.target_type is not None:
+                rqlst.add_type_restriction(var, self.target_type)
             try:
                 rset = self.rqlexec(rqlst.as_string(), self.cw_rset.args, self.cw_rset.cachekey)
             except: