# HG changeset patch # User Goffi # Date 1547894342 -3600 # Node ID 442ab697f831a92a454c040f112b9b7d20ebf2d7 # Parent b17e6fa1e607f6a236b35e8139109b7d07ba2d08 frontends, jp, templates: added XHTMLBox widget: for jp, the XHTML is rendered for now using markdown. diff -r b17e6fa1e607 -r 442ab697f831 sat/tools/common/template_xmlui.py --- a/sat/tools/common/template_xmlui.py Sat Jan 19 11:39:02 2019 +0100 +++ b/sat/tools/common/template_xmlui.py Sat Jan 19 11:39:02 2019 +0100 @@ -27,6 +27,12 @@ log = getLogger(__name__) from sat_frontends.tools import xmlui from functools import partial +try: + from jinja2 import Markup as safe +except ImportError: + # Safe marks XHTML values as usable as it. + # If jinja2 is not there, we can use a simple lamba + safe = lambda x: x ## Widgets ## @@ -136,6 +142,17 @@ type = u"textbox" +class XHTMLBoxWidget(xmlui.XHTMLBoxWidget, InputWidget): + type = u"xhtmlbox" + + def __init__(self, xmlui_parent, value, read_only=False): + # XXX: XHTMLBoxWidget value must be cleaned (harmful XHTML must be removed) + # This is normally done in the backend, the frontends should not need to + # worry about it. + super(XHTMLBoxWidget, self).__init__( + xmlui_parent=xmlui_parent, value=safe(value), read_only=read_only) + + class ListWidget(xmlui.ListWidget, OptionsWidget): type = u"list" diff -r b17e6fa1e607 -r 442ab697f831 sat_frontends/jp/xmlui_manager.py --- a/sat_frontends/jp/xmlui_manager.py Sat Jan 19 11:39:02 2019 +0100 +++ b/sat_frontends/jp/xmlui_manager.py Sat Jan 19 11:39:02 2019 +0100 @@ -238,6 +238,18 @@ type = u"textbox" +class XHTMLBoxWidget(xmlui_base.XHTMLBoxWidget, StringWidget): + type = u"xhtmlbox" + + def show(self): + # FIXME: we use bridge in a blocking way as permitted by python-dbus + # this only for now to make it simpler, it must be refactored + # to use async when jp will be fully async (expected for 0.8) + self.value = self.host.bridge.syntaxConvert( + self.value, C.SYNTAX_XHTML, "markdown", False, self.host.profile) + super(XHTMLBoxWidget, self).show() + + class ListWidget(xmlui_base.ListWidget, OptionsWidget): type = u"list" # TODO: handle flags, notably multi diff -r b17e6fa1e607 -r 442ab697f831 sat_frontends/tools/xmlui.py --- a/sat_frontends/tools/xmlui.py Sat Jan 19 11:39:02 2019 +0100 +++ b/sat_frontends/tools/xmlui.py Sat Jan 19 11:39:02 2019 +0100 @@ -116,12 +116,22 @@ class TextBoxWidget(Widget): """Input widget with require a long, possibly multilines string + often called TextArea in toolkits """ pass +class XHTMLBoxWidget(Widget): + """Input widget specialised in XHTML editing, + + a WYSIWYG or specialised editor is expected + """ + + pass + + class BoolWidget(Widget): """Input widget with require a boolean value often called CheckBox in toolkits @@ -582,6 +592,11 @@ _xmlui_parent, value, self._isAttrSet("read_only", node) ) self.ctrl_list[name] = {"type": type_, "control": ctrl} + elif type_ == "xhtmlbox": + ctrl = self.widget_factory.createXHTMLBoxWidget( + _xmlui_parent, value, self._isAttrSet("read_only", node) + ) + self.ctrl_list[name] = {"type": type_, "control": ctrl} elif type_ == "bool": ctrl = self.widget_factory.createBoolWidget( _xmlui_parent,