backport stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 01 Jul 2011 15:26:33 +0200
changeset 7604 1eb6090311ff
parent 7600 75d208ab8444 (current diff)
parent 7603 1302aa6ba4da (diff)
child 7605 48abeac162fd
backport stable
schema.py
test/unittest_schema.py
web/data/cubicweb.facets.js
web/facet.py
--- a/schema.py	Fri Jul 01 13:39:45 2011 +0200
+++ b/schema.py	Fri Jul 01 15:26:33 2011 +0200
@@ -646,9 +646,10 @@
 
 def split_expression(rqlstring):
     for expr in rqlstring.split(','):
-        for noparen in expr.split('('):
-            for word in noparen.split():
-                yield word
+        for noparen1 in expr.split('('):
+            for noparen2 in noparen1.split(')'):
+                for word in noparen2.split():
+                    yield word
 
 def normalize_expression(rqlstring):
     """normalize an rql expression to ease schema synchronization (avoid
--- a/test/unittest_schema.py	Fri Jul 01 13:39:45 2011 +0200
+++ b/test/unittest_schema.py	Fri Jul 01 15:26:33 2011 +0200
@@ -320,8 +320,8 @@
 
 class GuessRrqlExprMainVarsTC(TestCase):
     def test_exists(self):
-        mainvars = guess_rrqlexpr_mainvars(normalize_expression('NOT EXISTS(O team_competition C, C level < 3)'))
-        self.assertEqual(mainvars, set(['O']))
+        mainvars = guess_rrqlexpr_mainvars(normalize_expression('NOT EXISTS(O team_competition C, C level < 3, C concerns S)'))
+        self.assertEqual(mainvars, set(['S', 'O']))
 
 
 if __name__ == '__main__':
--- a/web/data/cubicweb.facets.js	Fri Jul 01 13:39:45 2011 +0200
+++ b/web/data/cubicweb.facets.js	Fri Jul 01 15:26:33 2011 +0200
@@ -133,11 +133,20 @@
         //       may changes and we must send its value when the callback is
         //       called, not when the page is initialized
         var facetargs = form.attr('cubicweb:facetargs');
-        if (facetargs !== undefined) {
+        if (facetargs != undefined && !form.attr('cubicweb:initialized')) {
+	    form.attr('cubicweb:initialized', '1');
+	    var jsfacetargs = cw.evalJSON(form.attr('cubicweb:facetargs'));
             form.submit(function() {
-                buildRQL.apply(null, cw.evalJSON(form.attr('cubicweb:facetargs')));
+                buildRQL.apply(null, jsfacetargs);
                 return false;
             });
+	    var divid = jsfacetargs[0];
+	    if (jQuery('#'+divid).length) {
+		var $loadingDiv = $(DIV({id:'facetLoading'},
+					facetLoadingMsg));
+		$loadingDiv.corner();
+		$(jQuery('#'+divid).get(0).parentNode).append($loadingDiv);
+	    }
             form.find('div.facet').each(function() {
                 var facet = jQuery(this);
                 facet.find('div.facetCheckBox').each(function(i) {
@@ -188,7 +197,7 @@
                         var $img = jQuery(this).find('img');
                         $img.attr('src', SELECTED_IMG).attr('alt', (_('selected')));
                     }
-                    buildRQL.apply(null, cw.evalJSON(form.attr('cubicweb:facetargs')));
+                    buildRQL.apply(null, jsfacetargs);
                     facet.find('.facetBody').animate({
                         scrollTop: 0
                     },
@@ -197,7 +206,7 @@
                 facet.find('select.facetOperator').change(function() {
                     var nbselected = facet.find('div.facetValueSelected').length;
                     if (nbselected >= 2) {
-                        buildRQL.apply(null, cw.evalJSON(form.attr('cubicweb:facetargs')));
+                        buildRQL.apply(null, jsfacetargs);
                     }
                 });
                 facet.find('div.facetTitle').click(function() {
--- a/web/facet.py	Fri Jul 01 13:39:45 2011 +0200
+++ b/web/facet.py	Fri Jul 01 15:26:33 2011 +0200
@@ -94,7 +94,7 @@
 def prepare_facets_rqlst(rqlst, args=None):
     """prepare a syntax tree to generate facet filters
 
-    * remove ORDERBY clause
+    * remove ORDERBY/GROUPBY clauses
     * cleanup selection (remove everything)
     * undefine unnecessary variables
     * set DISTINCT
@@ -106,8 +106,10 @@
     select.set_limit(None)
     select.set_offset(None)
     baserql = select.as_string(kwargs=args)
-    # cleanup sort terms
+    # cleanup sort terms / group by
     select.remove_sort_terms()
+    select.remove_groups()
+    # XXX remove aggregat from having
     # selection: only vocabulary entity
     for term in select.selection[:]:
         select.remove_selected(term)
--- a/web/test/unittest_facet.py	Fri Jul 01 13:39:45 2011 +0200
+++ b/web/test/unittest_facet.py	Fri Jul 01 15:26:33 2011 +0200
@@ -66,18 +66,18 @@
         self.assertEqual(f.vocabulary(),
                           [(u'guests', guests), (u'managers', managers)])
         # ensure rqlst is left unmodified
-        self.assertEqual(rqlst.as_string(), 'DISTINCT Any  GROUPBY X WHERE X in_group G?, G name GN, NOT G name "users"')
+        self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X in_group G?, G name GN, NOT G name "users"')
         #rqlst = rset.syntax_tree()
         self.assertEqual(sorted(f.possible_values()),
                           [str(guests), str(managers)])
         # ensure rqlst is left unmodified
-        self.assertEqual(rqlst.as_string(), 'DISTINCT Any  GROUPBY X WHERE X in_group G?, G name GN, NOT G name "users"')
+        self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X in_group G?, G name GN, NOT G name "users"')
         req.form[f.__regid__] = str(guests)
         f.add_rql_restrictions()
         # selection is cluttered because rqlst has been prepared for facet (it
         # is not in real life)
-        self.assertEqual(f.rqlst.as_string(),
-                          'DISTINCT Any  GROUPBY X WHERE X in_group G?, G name GN, NOT G name "users", X in_group D, D eid %s' % guests)
+        self.assertEqual(f.select.as_string(),
+                          'DISTINCT Any  WHERE X in_group G?, G name GN, NOT G name "users", X in_group D, D eid %s' % guests)
 
     def test_relation_no_relation_1(self):
         f, (guests, managers) = self._in_group_facet(no_relation=True)