changeset 504:f030491cff75

browser side (XMLUI): fixed bad use of text instead of XHTML in dialogs
author Goffi <goffi@goffi.org>
date Wed, 20 Aug 2014 20:59:13 +0200
parents 88ece2a00c63
children f0b56c022c01
files src/browser/sat_browser/html_tools.py src/browser/sat_browser/xmlui.py
diffstat 2 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/sat_browser/html_tools.py	Thu Aug 14 13:27:07 2014 +0200
+++ b/src/browser/sat_browser/html_tools.py	Wed Aug 20 20:59:13 2014 +0200
@@ -29,19 +29,20 @@
     """Naive sanitization of HTML"""
     return html.replace('<', '&lt;').replace('>', '&gt;')
 
-
 def html_strip(html):
     """Strip leading/trailing white spaces, HTML line breaks and &nbsp; sequences."""
     cleaned = re.sub(r"^(<br/?>|&nbsp;|\s)+", "", html)
     cleaned = re.sub(r"(<br/?>|&nbsp;|\s)+$", "", cleaned)
     return cleaned
 
-
 def inlineRoot(xhtml):
     """ make root element inline """
     doc = dom.parseString(xhtml)
     return xmltools.inlineRoot(doc)
 
-
 def convertNewLinesToXHTML(text):
     return text.replace('\n', '<br/>')
+
+def XHTML2Text(xhtml):
+    """Helper method to apply both html_sanitize and convertNewLinesToXHTML"""
+    return convertNewLinesToXHTML(html_sanitize(xhtml))
--- a/src/browser/sat_browser/xmlui.py	Thu Aug 14 13:27:07 2014 +0200
+++ b/src/browser/sat_browser/xmlui.py	Wed Aug 20 20:59:13 2014 +0200
@@ -20,8 +20,10 @@
 from sat.core.log import getLogger
 log = getLogger(__name__)
 from sat_frontends.tools import xmlui
+from sat_frontends.tools import strings
 from sat_browser.constants import Const as C
 from sat_browser import dialog
+from sat_browser import html_tools
 
 from pyjamas.ui.VerticalPanel import VerticalPanel
 from pyjamas.ui.HorizontalPanel import HorizontalPanel
@@ -309,6 +311,8 @@
 
     def __init__(self, _xmlui_parent, title, message, level):
         #TODO: level is not managed
+        title = html_tools.html_sanitize(title)
+        message = strings.addURLToText(html_tools.XHTML2Text(message))
         Dlg.__init__(self)
         xmlui.MessageDialog.__init__(self, _xmlui_parent)
         dialog.InfoDialog.__init__(self, title, message, self._xmluiValidated())
@@ -326,8 +330,9 @@
 
     def __init__(self, _xmlui_parent, title, message, level):
         #TODO: level is not managed
+        title = html_tools.html_sanitize(title)
+        message = strings.addURLToText(html_tools.XHTML2Text(message))
         xmlui.ConfirmDialog.__init__(self, _xmlui_parent)
-        print "self.parent = %s" % self._xmlui_parent
         Dlg.__init__(self)
         dialog.ConfirmDialog.__init__(self, self.answered, message, title)