fix the bad rqlst syntax tree usage during facets initialization by copying it stable
authorCharles Hébert <charles.hebert@logilab.fr>
Wed, 17 Feb 2010 15:57:03 +0100
branchstable
changeset 4614 95ccd84c892b
parent 4613 141a4f613f8a
child 4615 d69d7ccbe046
fix the bad rqlst syntax tree usage during facets initialization by copying it
web/facet.py
web/views/facets.py
--- a/web/facet.py	Wed Feb 17 10:39:35 2010 +0100
+++ b/web/facet.py	Wed Feb 17 15:57:03 2010 +0100
@@ -268,25 +268,16 @@
     needs_update = False
     start_unfolded = True
 
-    def __init__(self, req, rset=None, rqlst=None, filtered_variable=None,
+    def __init__(self, req, rqlst=None, filtered_variable=None,
                  **kwargs):
-        super(AbstractFacet, self).__init__(req, rset=rset, **kwargs)
-        assert rset is not None or rqlst is not None
+        super(AbstractFacet, self).__init__(req, **kwargs)
+        assert rqlst is not None
         assert filtered_variable
-        # facet retreived using `object_by_id` from an ajax call
-        if rset is None:
-            self.init_from_form(rqlst=rqlst)
-        # facet retreived from `select` using the result set to filter
-        else:
-            self.init_from_rset()
+        # take care: facet may be retreived using `object_by_id` from an ajax call
+        # or from `select` using the result set to filter
+        self.rqlst = rqlst
         self.filtered_variable = filtered_variable
 
-    def init_from_rset(self):
-        self.rqlst = self.cw_rset.syntax_tree().children[0]
-
-    def init_from_form(self, rqlst):
-        self.rqlst = rqlst
-
     @property
     def operator(self):
         # OR between selected values by default
--- a/web/views/facets.py	Wed Feb 17 10:39:35 2010 +0100
+++ b/web/views/facets.py	Wed Feb 17 15:57:03 2010 +0100
@@ -71,35 +71,32 @@
             return
         if vid is None:
             vid = req.form.get('vid')
-        rqlst = rset.syntax_tree()
-        rqlst.save_state()
-        try:
-            mainvar, baserql = prepare_facets_rqlst(rqlst, rset.args)
-            widgets = []
-            for facet in self.get_facets(rset, mainvar):
-                if facet.cw_propval('visible'):
-                    wdg = facet.get_widget()
-                    if wdg is not None:
-                        widgets.append(wdg)
-            if not widgets:
-                return
-            if self.bk_linkbox_template:
-                self.display_bookmark_link(rset)
-            w = self.w
-            w(u'<form method="post" id="%sForm" cubicweb:facetargs="%s" action="">'  % (
-                divid, xml_escape(dumps([divid, vid, paginate, self.facetargs()]))))
-            w(u'<fieldset>')
-            hiddens = {'facets': ','.join(wdg.facet.__regid__ for wdg in widgets),
-                       'baserql': baserql}
-            for param in ('subvid', 'vtitle'):
-                if param in req.form:
-                    hiddens[param] = req.form[param]
-            filter_hiddens(w, **hiddens)
-            for wdg in widgets:
-                wdg.render(w=self.w)
-            w(u'</fieldset>\n</form>\n')
-        finally:
-            rqlst.recover()
+        rqlst = rset.syntax_tree().copy()
+        req.vreg.rqlhelper.annotate(rqlst)
+        mainvar, baserql = prepare_facets_rqlst(rqlst, rset.args)
+        widgets = []
+        for facet in self.get_facets(rset, rqlst.children[0], mainvar):
+            if facet.cw_propval('visible'):
+                wdg = facet.get_widget()
+                if wdg is not None:
+                    widgets.append(wdg)
+        if not widgets:
+            return
+        if self.bk_linkbox_template:
+            self.display_bookmark_link(rset)
+        w = self.w
+        w(u'<form method="post" id="%sForm" cubicweb:facetargs="%s" action="">'  % (
+            divid, xml_escape(dumps([divid, vid, paginate, self.facetargs()]))))
+        w(u'<fieldset>')
+        hiddens = {'facets': ','.join(wdg.facet.__regid__ for wdg in widgets),
+                   'baserql': baserql}
+        for param in ('subvid', 'vtitle'):
+            if param in req.form:
+                hiddens[param] = req.form[param]
+        filter_hiddens(w, **hiddens)
+        for wdg in widgets:
+            wdg.render(w=self.w)
+        w(u'</fieldset>\n</form>\n')
 
     def display_bookmark_link(self, rset):
         eschema = self._cw.vreg.schema.eschema('Bookmark')
@@ -115,10 +112,10 @@
                     self._cw._('bookmark this search'))
             self.w(self.bk_linkbox_template % bk_link)
 
-    def get_facets(self, rset, mainvar):
-        return self._cw.vreg['facets'].poss_visible_objects(self._cw, rset=rset,
-                                                        context='facetbox',
-                                                        filtered_variable=mainvar)
+    def get_facets(self, rset, rqlst, mainvar):
+        return self._cw.vreg['facets'].poss_visible_objects(
+            self._cw, rset=rset, rqlst=rqlst,
+            context='facetbox', filtered_variable=mainvar)
 
 # facets ######################################################################