merge 3.16.x fix in 3.17.x branch
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Wed, 24 Apr 2013 15:37:43 +0200
changeset 8916 2a424950463d
parent 8915 c5c6da8e42db (current diff)
parent 8914 e80dfffc2c2a (diff)
child 8917 685b93559e33
merge 3.16.x fix in 3.17.x branch
server/repository.py
server/sources/native.py
--- a/cwvreg.py	Wed Apr 24 15:33:49 2013 +0200
+++ b/cwvreg.py	Wed Apr 24 15:37:43 2013 +0200
@@ -297,6 +297,10 @@
         super(ETypeRegistry, self).initialization_completed()
         # clear etype cache if you don't want to run into deep weirdness
         self.clear_caches()
+        # rebuild all classes to avoid potential memory fragmentation
+        # (see #2719113)
+        for eschema in self.vreg.schema.entities():
+            self.etype_class(eschema)
 
     def register(self, obj, **kwargs):
         obj = related_appobject(obj)
--- a/server/repository.py	Wed Apr 24 15:33:49 2013 +0200
+++ b/server/repository.py	Wed Apr 24 15:37:43 2013 +0200
@@ -985,7 +985,7 @@
         self.debug('cleaning session unused since %s',
                    strftime('%T', localtime(mintime)))
         nbclosed = 0
-        for session in self._sessions.itervalues():
+        for session in self._sessions.values():
             if session.timestamp < mintime:
                 self.close(session.id)
                 nbclosed += 1
--- a/server/sources/native.py	Wed Apr 24 15:33:49 2013 +0200
+++ b/server/sources/native.py	Wed Apr 24 15:37:43 2013 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -1715,7 +1715,7 @@
         return self._source.get_connection()
 
     def backup(self, backupfile):
-        archive=zipfile.ZipFile(backupfile, 'w', allowZip64=True)
+        archive = zipfile.ZipFile(backupfile, 'w', allowZip64=True)
         self.cnx = self.get_connection()
         try:
             self.cursor = self.cnx.cursor()
@@ -1750,7 +1750,7 @@
             etype_tables.append('%s%s'%(prefix, etype))
         for rtype in self.schema.relations():
             rschema = self.schema.rschema(rtype)
-            if rschema.final or rschema.inlined:
+            if rschema.final or rschema.inlined or rschema in VIRTUAL_RTYPES:
                 continue
             relation_tables.append('%s_relation' % rtype)
         return non_entity_tables + etype_tables + relation_tables
--- a/test/unittest_uilib.py	Wed Apr 24 15:33:49 2013 +0200
+++ b/test/unittest_uilib.py	Wed Apr 24 15:37:43 2013 +0200
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -23,7 +23,10 @@
 
 import pkg_resources
 
-from unittest2 import skipIf
+try:
+    from unittest import skipIf
+except ImportError:
+    from unittest2 import skipIf
 
 from logilab.common.testlib import DocTest, TestCase, unittest_main
 
--- a/web/data/cubicweb.facets.js	Wed Apr 24 15:33:49 2013 +0200
+++ b/web/data/cubicweb.facets.js	Wed Apr 24 15:37:43 2013 +0200
@@ -195,38 +195,13 @@
                             }
                             this.setAttribute('alt', (_("not selected")));
                         });
-                        var index = parseInt($this.attr('cubicweb:idx'));
-                        // we dont need to move the element when cubicweb:idx == 0
-                        if (index > 0) {
-                            var shift = $.grep(facet.find('.facetValueSelected'), function(n) {
-                                var nindex = parseInt(n.getAttribute('cubicweb:idx'));
-                                return nindex > index;
-                            }).length;
-                            index += shift;
-                            var parent = this.parentNode;
-                            var $insertAfter = $(parent).find('.facetCheckBox:nth(' + index + ')');
-                            if (! ($insertAfter.length == 1 && shift == 0)) {
-                                // only rearrange element if necessary
-                                $insertAfter.after(this);
-                            }
-                        }
                     } else {
-                        var lastSelected = facet.find('.facetValueSelected:last');
-                        if (lastSelected.length) {
-                            lastSelected.after(this);
-                        } else {
-                            var parent = this.parentNode;
-                            $(parent).prepend(this);
-                        }
                         $(this).addClass('facetValueSelected');
                         var $img = $(this).find('img');
                         $img.attr('src', SELECTED_IMG).attr('alt', (_("selected")));
                     }
+                    facetCheckBoxReorder(facet);
                     buildRQL.apply(null, jsfacetargs);
-                    facet.find('.facetBody').animate({
-                        scrollTop: 0
-                    },
-                    '');
                 });
                 facet.find('select.facetOperator').change(function() {
                     var nbselected = facet.find('div.facetValueSelected').length;
@@ -244,6 +219,29 @@
     });
 }
 
+// facetCheckBoxReorder: reorder all items according to cubicweb:idx attribute
+function facetCheckBoxReorder($facet) {
+    var sortfunc = function (a, b) {
+        // convert from string to integer
+        a = +a.getAttribute("cubicweb:idx");
+        b = +b.getAttribute("cubicweb:idx");
+        // compare
+        if (a > b) {
+            return 1;
+        } else if (a < b) {
+            return -1;
+        } else {
+            return 0;
+        }
+    };
+    var $items = $facet.find('.facetValue.facetValueSelected')
+    $items.sort(sortfunc);
+    $facet.find('.facetBody').append($items);
+    var $items = $facet.find('.facetValue:not(.facetValueSelected)')
+    $items.sort(sortfunc);
+    $facet.find('.facetBody').append($items);
+    $facet.find('.facetBody').animate({scrollTop: 0}, '');
+}
 
 // trigger this function on document ready event if you provide some kind of
 // persistent search (eg crih)
--- a/web/test/unittest_viewselector.py	Wed Apr 24 15:33:49 2013 +0200
+++ b/web/test/unittest_viewselector.py	Wed Apr 24 15:37:43 2013 +0200
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -47,11 +47,6 @@
                  cwsources.ManageSourcesAction,
                  debug.SiteInfoAction]
 
-if hasattr(rdf, 'RDFView') is not None: # not available if rdf lib not installed
-    RDFVIEWS = [('rdf', rdf.RDFView)]
-
-assert RDFVIEWS
-
 if hasattr(rdf, 'RDFView'): # not available if rdflib not installed
     RDFVIEWS = [('rdf', rdf.RDFView)]
 else: