backport stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 07 Oct 2010 19:04:07 +0200
changeset 6409 d75535983224
parent 6404 2013ef8f56e9 (current diff)
parent 6408 7674f674de40 (diff)
child 6413 c1a85c1ce131
backport stable
devtools/testlib.py
utils.py
web/views/boxes.py
--- a/utils.py	Wed Oct 06 14:57:14 2010 +0200
+++ b/utils.py	Thu Oct 07 19:04:07 2010 +0200
@@ -218,6 +218,11 @@
     javascripts and stylesheets
     """
     js_unload_code = u'jQuery(window).unload(unloadPageData);'
+    # Making <script> tag content work properly with all possible
+    # content-types (xml/html) and all possible browsers is very
+    # tricky, see http://www.hixie.ch/advocacy/xhtml for an in-depth discussion
+    xhtml_safe_script_opening = u'<script type="text/javascript"><!--//--><![CDATA[//><!--\n'
+    xhtml_safe_script_closing = u'\n//--><!]]></script>'
 
     def __init__(self):
         super(HTMLHead, self).__init__()
@@ -291,14 +296,14 @@
         w = self.write
         # 1/ variable declaration if any
         if self.jsvars:
-            w(u'<script type="text/javascript"><!--//--><![CDATA[//><!--\n')
+            w(self.xhtml_safe_script_opening)
             for var, value, override in self.jsvars:
                 vardecl = u'%s = %s;' % (var, json.dumps(value))
                 if not override:
                     vardecl = (u'if (typeof %s == "undefined") {%s}' %
                                (var, vardecl))
                 w(vardecl + u'\n')
-            w(u'//--><!]]></script>\n')
+            w(self.xhtml_safe_script_closing)
         # 2/ css files
         for cssfile, media in self.cssfiles:
             w(u'<link rel="stylesheet" type="text/css" media="%s" href="%s"/>\n' %
@@ -316,9 +321,9 @@
               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')
+            w(self.xhtml_safe_script_opening)
             w(u'\n\n'.join(self.post_inlined_scripts))
-            w(u'\n</script>\n')
+            w(self.xhtml_safe_script_closing)
         header = super(HTMLHead, self).getvalue()
         if skiphead:
             return header
--- a/web/views/boxes.py	Wed Oct 06 14:57:14 2010 +0200
+++ b/web/views/boxes.py	Thu Oct 07 19:04:07 2010 +0200
@@ -235,6 +235,9 @@
 
     def call(self, **kwargs):
         """display a list of entities by calling their <item_vid> view"""
+        if 'dispctrl' in self.cw_extra_kwargs:
+            # XXX do not modify dispctrl!
+            self.cw_extra_kwargs['dispctrl'].setdefault('subvid', 'outofcontext')
         box = self._cw.vreg['ctxcomponents'].select(
             'rsetbox', self._cw, rset=self.cw_rset, vid='autolimited',
             title=title, **self.cw_extra_kwargs)
--- a/web/views/dotgraphview.py	Wed Oct 06 14:57:14 2010 +0200
+++ b/web/views/dotgraphview.py	Thu Oct 07 19:04:07 2010 +0200
@@ -31,14 +31,15 @@
 
 class DotGraphView(EntityView):
     __abstract__ = True
-
+    backend_class = DotBackend
+    backend_kwargs = {'ratio': 'compress', 'size': '30,10'}
     def cell_call(self, row, col):
         entity = self.cw_rset.get_entity(row, col)
         visitor = self.build_visitor(entity)
         prophdlr = self.build_dotpropshandler()
         graphname = 'dotgraph%s' % str(entity.eid)
-        generator = GraphGenerator(DotBackend(graphname, None,
-                                              ratio='compress', size='30,10'))
+        generator = GraphGenerator(self.backend_class(graphname, None,
+                                                      **self.backend_kwargs))
         # map file
         pmap, mapfile = tempfile.mkstemp(".map", graphname)
         os.close(pmap)
@@ -50,7 +51,7 @@
         self._cw.session.data[filekeyid] = tmpfile
         self.w(u'<img src="%s" alt="%s" usemap="#%s" />' % (
             xml_escape(entity.absolute_url(vid='tmppng', tmpfile=filekeyid)),
-            xml_escape(self._cw._('Data connection graph for %s') % entity.name),
+            xml_escape(self._cw._('Data connection graph for %s') % entity.dc_title()),
             graphname))
         stream = open(mapfile, 'r').read()
         stream = stream.decode(self._cw.encoding)
@@ -61,7 +62,7 @@
         raise NotImplementedError
 
     def build_dotpropshandler(self):
-        return DotGraphPropsHandler(self._cw)
+        return DotPropsHandler(self._cw)
 
 
 class DotPropsHandler(object):