facets enhancement: can now set label_vid to use a view instead of a simple attribute as label stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 18 Sep 2009 19:49:54 +0200
branchstable
changeset 3328 76888cd23d83
parent 3327 44efba78afac
child 3329 8430f6c693a1
facets enhancement: can now set label_vid to use a view instead of a simple attribute as label
web/facet.py
--- a/web/facet.py	Fri Sep 18 19:48:58 2009 +0200
+++ b/web/facet.py	Fri Sep 18 19:49:54 2009 +0200
@@ -346,6 +346,8 @@
     sortfunc = None
     # ascendant/descendant sorting
     sortasc = True
+    # if you want to call a view on the entity instead of using `target_attr`
+    label_vid = None
 
     @property
     def title(self):
@@ -384,8 +386,14 @@
             rqlst.recover()
 
     def rset_vocabulary(self, rset):
-        _ = self.req._
-        return [(_(label), eid) for eid, label in rset]
+        if self.label_vid is None:
+            _ = self.req._
+            return [(_(label), eid) for eid, label in rset]
+        if self.sortfunc is None:
+            return sorted((entity.view(self.label_vid), entity.eid)
+                          for entity in rset.entities())
+        return [(entity.view(self.label_vid), entity.eid)
+                for entity in rset.entities()]
 
     @cached
     def support_and(self):