backport stable into 3.5 3.5
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Wed, 02 Sep 2009 18:10:36 +0200
branch3.5
changeset 3101 e75ab3635f07
parent 3100 b0a583156d6d (current diff)
parent 3099 006be45923da (diff)
child 3103 1d09765ee720
backport stable into 3.5
utils.py
--- a/utils.py	Wed Sep 02 17:47:39 2009 +0200
+++ b/utils.py	Wed Sep 02 18:10:36 2009 +0200
@@ -7,6 +7,8 @@
 """
 __docformat__ = "restructuredtext en"
 
+from logilab.mtconverter import xml_escape
+
 import locale
 from md5 import md5
 from datetime import datetime, timedelta, date
@@ -262,17 +264,18 @@
         # 2/ css files
         for cssfile, media in self.cssfiles:
             w(u'<link rel="stylesheet" type="text/css" media="%s" href="%s"/>\n' %
-              (media, cssfile))
+              (media, xml_escape(cssfile)))
         # 3/ ie css if necessary
         if self.ie_cssfiles:
             w(u'<!--[if lt IE 8]>\n')
             for cssfile, media in self.ie_cssfiles:
                 w(u'<link rel="stylesheet" type="text/css" media="%s" href="%s"/>\n' %
-                  (media, cssfile))
+                  (media, xml_escape(cssfile)))
             w(u'<![endif]--> \n')
         # 4/ js files
         for jsfile in self.jsfiles:
-            w(u'<script type="text/javascript" src="%s"></script>\n' % jsfile)
+            w(u'<script type="text/javascript" src="%s"></script>\n' %
+              xml_escape(jsfile))
         # 5/ post inlined scripts (i.e. scripts depending on other JS files)
         if self.post_inlined_scripts:
             w(u'<script type="text/javascript">\n')
@@ -305,7 +308,8 @@
         self.htmltag = u'<html xmlns="http://www.w3.org/1999/xhtml" ' \
                        'xmlns:cubicweb="http://www.logilab.org/2008/cubicweb" ' \
                        'xml:lang="%s" lang="%s">' % (req.lang, req.lang)
-
+        # keep main_stream's reference on req for easier text/html demoting
+        req.main_stream = self
 
     def write(self, data):
         """StringIO interface: this method will be assigned to self.w
--- a/web/data/cubicweb.calendar.js	Wed Sep 02 17:47:39 2009 +0200
+++ b/web/data/cubicweb.calendar.js	Wed Sep 02 18:10:36 2009 +0200
@@ -112,7 +112,8 @@
 	this.domtable = TABLE({'class': this.cssclass},
 			      THEAD(null, TR(null,
 					     TH(null, A({'href' : prevlink}, "<<")),
-					     TH({'colspan' : 5, 'style' : "text-align: center;"}, monthname),
+					     // IE 6/7 requires colSpan instead of colspan
+					     TH({'colSpan': 5, 'colspan':5, 'style' : "text-align: center;"}, monthname),
 					     TH(null, A({'href' : nextlink}, ">>")))),
 			      TBODY(null,
 				    this._headdisplay(),
--- a/web/data/cubicweb.calendar_popup.css	Wed Sep 02 17:47:39 2009 +0200
+++ b/web/data/cubicweb.calendar_popup.css	Wed Sep 02 18:10:36 2009 +0200
@@ -24,17 +24,16 @@
 table.popupCalendar {
   text-align: center;
   border: 1px solid #ccc;
-  z-index: 100;
+  z-index: 400;
 }
 
-
 table.popupCalendar th {
+  border:1px solid #ccc;
   background : #d9d9c1;
   color: black;
   padding: 2px 3px;
 }
 
-
 table.popupCalendar th.calTitle,
 table.popupCalendar th.prev,
 table.popupCalendar th.next {
@@ -51,12 +50,12 @@
   padding: 2px 0px;
 }
 
-
 table.popupCalendar td {
   width: 2em;
   height: 2em;
   background : #f6f5e1;
   font-size: 85%;
+  border:1px solid #ccc;
 }
 
 table.popupCalendar td.today {
--- a/web/data/cubicweb.compat.js	Wed Sep 02 17:47:39 2009 +0200
+++ b/web/data/cubicweb.compat.js	Wed Sep 02 18:10:36 2009 +0200
@@ -172,7 +172,7 @@
 		}
 		node[key] = value;
 	    } else { // normal node attribute
-		node.setAttribute(key, params[key]);
+		jQuery(node).attr(key, params[key]);
 	    }
 	}
 	if (children) {
--- a/web/request.py	Wed Sep 02 17:47:39 2009 +0200
+++ b/web/request.py	Wed Sep 02 18:10:36 2009 +0200
@@ -26,7 +26,7 @@
 from cubicweb.common.mail import header
 from cubicweb.common.uilib import remove_html_tags
 from cubicweb.utils import SizeConstrainedList, HTMLHead
-from cubicweb.view import STRICT_DOCTYPE
+from cubicweb.view import STRICT_DOCTYPE, TRANSITIONAL_DOCTYPE_NOEXT
 from cubicweb.web import (INTERNAL_FIELD_VALUE, LOGGER, NothingToEdit,
                           RequestError, StatusResponse)
 
@@ -663,6 +663,16 @@
         """
         raise NotImplementedError()
 
+    def demote_to_html(self):
+        """helper method to dynamically set request content type to text/html
+
+        The global doctype and xmldec must also be changed otherwise the browser
+        will display '<[' at the beginning of the page
+        """
+        self.set_content_type('text/html')
+        self.main_stream.doctype = TRANSITIONAL_DOCTYPE_NOEXT
+        self.main_stream.xmldecl = u''
+
     # page data management ####################################################
 
     def get_page_data(self, key, default=None):
--- a/web/views/editcontroller.py	Wed Sep 02 17:47:39 2009 +0200
+++ b/web/views/editcontroller.py	Wed Sep 02 18:10:36 2009 +0200
@@ -191,7 +191,22 @@
             return
         attrtype = rschema.objects(entity.e_schema)[0].type
         # on checkbox or selection, the field may not be in params
-        if attrtype == 'Boolean':
+        # NOTE: raising ValidationError here is not a good solution because
+        #       we can't gather all errors at once. Hopefully, the new 3.6.x
+        #       form handling will fix that
+        if attrtype == 'Int':
+            try:
+                value = int(value)
+            except ValueError:
+                raise ValidationError(entity.eid,
+                                      {attr: self.req._("invalid integer value")})
+        elif attrtype == 'Float':
+            try:
+                value = float(value)
+            except ValueError:
+                raise ValidationError(entity.eid,
+                                      {attr: self.req._("invalid float value")})
+        elif attrtype == 'Boolean':
             value = bool(value)
         elif attrtype == 'Decimal':
             value = Decimal(value)
--- a/web/views/igeocodable.py	Wed Sep 02 17:47:39 2009 +0200
+++ b/web/views/igeocodable.py	Wed Sep 02 18:10:36 2009 +0200
@@ -74,6 +74,7 @@
     need_navigation = False
 
     def call(self, gmap_key, width=400, height=400, uselabel=True, urlparams=None):
+        self.req.demote_to_html()
         # remove entities that don't define latitude and longitude
         self.rset = self.rset.filtered_rset(lambda e: e.latitude and e.longitude)
         self.req.add_js('http://maps.google.com/maps?sensor=false&file=api&amp;v=2&amp;key=%s' % gmap_key,
--- a/web/views/plots.py	Wed Sep 02 17:47:39 2009 +0200
+++ b/web/views/plots.py	Wed Sep 02 18:10:36 2009 +0200
@@ -103,7 +103,7 @@
 
     def _render(self, req, width=500, height=400):
         # XXX IE requires excanvas.js
-        req.add_js( ('jquery.flot.js', 'cubicweb.flot.js') )
+        req.add_js( ('jquery.flot.js', 'cubicweb.flot.js', 'excanvas.js') )
         figid = u'figure%s' % make_uid('foo')
         plotdefs = []
         plotdata = []