backport stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 28 Jun 2011 16:33:53 +0200
changeset 7569 02c338197322
parent 7565 b355d9dd43df (current diff)
parent 7568 c5ee33fb6a3b (diff)
child 7570 648bf83945a5
backport stable
server/serverctl.py
test/unittest_utils.py
utils.py
web/views/plots.py
--- a/doc/book/en/tutorials/advanced/part03_bfss.rst	Mon Jun 27 18:48:30 2011 +0200
+++ b/doc/book/en/tutorials/advanced/part03_bfss.rst	Tue Jun 28 16:33:53 2011 +0200
@@ -32,7 +32,7 @@
                 makedirs(bfssdir)
                 print 'created', bfssdir
             storage = storages.BytesFileSystemStorage(bfssdir)
-            set_attribute_storage(self.repo, 'File', 'data', storage)
+            storages.set_attribute_storage(self.repo, 'File', 'data', storage)
 
 .. Note::
 
--- a/server/serverctl.py	Mon Jun 27 18:48:30 2011 +0200
+++ b/server/serverctl.py	Tue Jun 28 16:33:53 2011 +0200
@@ -356,7 +356,7 @@
                         print '-> user %s created.' % user
                 if dbname in helper.list_databases(cursor):
                     if automatic or ASK.confirm('Database %s already exists -- do you want to drop it ?' % dbname):
-                        cursor.execute('DROP DATABASE %s' % dbname)
+                        cursor.execute('DROP DATABASE "%s"' % dbname)
                     else:
                         print ('you may want to run "cubicweb-ctl db-init '
                                '--drop %s" manually to continue.' % config.appid)
--- a/test/unittest_uilib.py	Mon Jun 27 18:48:30 2011 +0200
+++ b/test/unittest_uilib.py	Tue Jun 28 16:33:53 2011 +0200
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -22,14 +22,15 @@
 
 
 import pkg_resources
-from logilab.common.testlib import TestCase, unittest_main
+
 from unittest2 import skipIf
 
+from logilab.common.testlib import DocTest, TestCase, unittest_main
+
 from cubicweb import uilib
 
 lxml_version = pkg_resources.get_distribution('lxml').version.split('.')
 
-
 class UILIBTC(TestCase):
 
     def test_remove_tags(self):
@@ -185,6 +186,10 @@
         self.assertMultiLineEqual(uilib.soup2xhtml(incoming, 'ascii'), expected)
 
 
+class DocTest(DocTest):
+    module = uilib
+
+
 if __name__ == '__main__':
     unittest_main()
 
--- a/test/unittest_utils.py	Mon Jun 27 18:48:30 2011 +0200
+++ b/test/unittest_utils.py	Tue Jun 28 16:33:53 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -21,9 +21,12 @@
 import decimal
 import datetime
 
-from logilab.common.testlib import TestCase, unittest_main
+
+from logilab.common.testlib import TestCase, DocTest, unittest_main
+
 from cubicweb.devtools.testlib import CubicWebTC
-from cubicweb.utils import make_uid, UStringIO, SizeConstrainedList, RepeatList, HTMLHead
+from cubicweb.utils import (make_uid, UStringIO, SizeConstrainedList,
+                            RepeatList, HTMLHead)
 from cubicweb.entity import Entity
 
 try:
@@ -252,5 +255,8 @@
 """
         self.assertEqual(result, expected)
 
+class DocTest(DocTest):
+    from cubicweb import utils as module
+
 if __name__ == '__main__':
     unittest_main()
--- a/utils.py	Mon Jun 27 18:48:30 2011 +0200
+++ b/utils.py	Tue Jun 28 16:33:53 2011 +0200
@@ -116,11 +116,11 @@
 
 
 class SizeConstrainedList(list):
-    """simple list that makes sure the list does not get bigger
-    than a given size.
+    """simple list that makes sure the list does not get bigger than a given
+    size.
 
-    when the list is full and a new element is added, the first
-    element of the list is removed before appending the new one
+    when the list is full and a new element is added, the first element of the
+    list is removed before appending the new one
 
     >>> l = SizeConstrainedList(2)
     >>> l.append(1)
@@ -128,6 +128,7 @@
     >>> l
     [1, 2]
     >>> l.append(3)
+    >>> l
     [2, 3]
     """
     def __init__(self, maxsize):
--- a/web/data/cubicweb.flot.js	Mon Jun 27 18:48:30 2011 +0200
+++ b/web/data/cubicweb.flot.js	Tue Jun 28 16:33:53 2011 +0200
@@ -13,16 +13,25 @@
 
 var previousPoint = null;
 function onPlotHover(event, pos, item) {
+    var $fig = $(event.target);
     if (item) {
         if (previousPoint != item.datapoint) {
             previousPoint = item.datapoint;
             $("#tooltip").remove();
             var x = item.datapoint[0].toFixed(2),
-            y = item.datapoint[1].toFixed(2);
-            if (item.datapoint.length == 3) {
-                x = new Date(item.datapoint[2]);
-                x = x.toLocaleDateString() + ' ' + x.toLocaleTimeString();
+                y = item.datapoint[1].toFixed(2);
+            if ($fig.data('mode') == 'time') {
+                x = new Date(item.datapoint[0]);
+                var dateformat = $fig.data('dateformat');
+                if (dateformat) {
+                    x = x.strftime(dateformat);
+                } else {
+                    x = x.toLocaleDateString() + ' ' + x.toLocaleTimeString();
+                }
             } else if (item.datapoint.length == 4) {
+                // NOTE: this has no chance to work with jquery flot >= 0.6 because
+                // jquery flot normalizes datapoints and only keeps 2 columns. Either
+                // use processRawData hook or use the 'dateformat' option.
                 x = new Date(item.datapoint[2]);
                 x = x.strftime(item.datapoint[3]);
             }
--- a/web/views/plots.py	Mon Jun 27 18:48:30 2011 +0200
+++ b/web/views/plots.py	Tue Jun 28 16:33:53 2011 +0200
@@ -82,15 +82,17 @@
 class FlotPlotWidget(PlotWidget):
     """PlotRenderer widget using Flot"""
     onload = u"""
-var fig = jQuery("#%(figid)s");
+var fig = jQuery('#%(figid)s');
 if (fig.attr('cubicweb:type') != 'prepared-plot') {
     %(plotdefs)s
-    jQuery.plot(jQuery("#%(figid)s"), [%(plotdata)s],
+    jQuery.plot(jQuery('#%(figid)s'), [%(plotdata)s],
         {points: {show: true},
          lines: {show: true},
          grid: {hoverable: true},
+         /*yaxis : {tickFormatter : suffixFormatter},*/
          xaxis: {mode: %(mode)s}});
-    jQuery("#%(figid)s").bind("plothover", onPlotHover);
+    jQuery('#%(figid)s').data({mode: %(mode)s, dateformat: %(dateformat)s});
+    jQuery('#%(figid)s').bind('plothover', onPlotHover);
     fig.attr('cubicweb:type','prepared-plot');
 }
 """
@@ -101,11 +103,8 @@
         self.timemode = timemode
 
     def dump_plot(self, plot):
-        # XXX for now, the only way that we have to customize properly
-        #     datetime labels on tooltips is to insert an additional column
-        #     cf. function onPlotHover in cubicweb.flot.js
         if self.timemode:
-            plot = [(datetime2ticks(x), y, datetime2ticks(x)) for x, y in plot]
+            plot = [(datetime2ticks(x), y) for x, y in plot]
         return json_dumps(plot)
 
     def _render(self, req, width=500, height=400):
@@ -122,11 +121,14 @@
             plotdefs.append('var %s = %s;' % (plotid, self.dump_plot(plot)))
             # XXX ugly but required in order to not crash my demo
             plotdata.append("{label: '%s', data: %s}" % (label.replace(u'&', u''), plotid))
+        fmt = req.property_value('ui.date-format') # XXX datetime-format
+        # XXX TODO make plot options customizable
         req.html_headers.add_onload(self.onload %
                                     {'plotdefs': '\n'.join(plotdefs),
                                      'figid': figid,
                                      'plotdata': ','.join(plotdata),
-                                     'mode': self.timemode and "'time'" or 'null'})
+                                     'mode': self.timemode and "'time'" or 'null',
+                                     'dateformat': '"%s"' % fmt})
 
 
 class PlotView(baseviews.AnyRsetView):