# HG changeset patch # User Goffi # Date 1589837824 -7200 # Node ID abca25af06d75107211ce30071320589a4b40168 # Parent 0c3b7ee2628fb0f32e281cc9625ddb719627dd68 plugin pubsub schema, tools (common/template xmlui): use a JID for publisher: - a JidWidget is used instead of text for publisher, nothing is set if publisher attribute doesn't exist - added missing JidWidget implementation in tools.common.template_xmlui diff -r 0c3b7ee2628f -r abca25af06d7 sat/plugins/plugin_exp_pubsub_schema.py --- a/sat/plugins/plugin_exp_pubsub_schema.py Mon May 18 23:31:55 2020 +0200 +++ b/sat/plugins/plugin_exp_pubsub_schema.py Mon May 18 23:37:04 2020 +0200 @@ -310,17 +310,23 @@ form = data_form.Form.fromElement(x_elt) if form_ns and form.formNamespace != form_ns: continue + prepend = [ + ("label", "id"), + ("text", item_elt["id"], "id"), + ("label", "publisher"), + ] + try: + publisher = jid.JID(item_elt['publisher']) + except (KeyError, jid.InvalidFormat): + pass + else: + prepend.append(("jid", publisher, "publisher")) xmlui = xml_tools.dataFormResult2XMLUI( form, schema_form, # FIXME: conflicts with schema (i.e. if "id" or "publisher" already exists) # are not checked - prepend=( - ("label", "id"), - ("text", item_elt["id"], "id"), - ("label", "publisher"), - ("text", item_elt.getAttribute("publisher", ""), "publisher"), - ), + prepend=prepend, filters=filters, read_only=False, ) diff -r 0c3b7ee2628f -r abca25af06d7 sat/tools/common/template_xmlui.py --- a/sat/tools/common/template_xmlui.py Mon May 18 23:31:55 2020 +0200 +++ b/sat/tools/common/template_xmlui.py Mon May 18 23:37:04 2020 +0200 @@ -22,11 +22,10 @@ XMLUI classes from this modules can then be iterated to create the template """ +from functools import partial from sat.core.log import getLogger - -log = getLogger(__name__) from sat_frontends.tools import xmlui -from functools import partial +from sat_frontends.tools import jid try: from jinja2 import Markup as safe except ImportError: @@ -35,6 +34,9 @@ safe = lambda x: x +log = getLogger(__name__) + + ## Widgets ## @@ -119,6 +121,13 @@ type = "text" +class JidWidget(xmlui.JidWidget, ValueWidget): + type = "jid" + + def __init__(self, xmlui_parent, value): + self.value = jid.JID(value) + + class LabelWidget(xmlui.LabelWidget, ValueWidget): type = "label" @@ -137,7 +146,6 @@ class JidInputWidget(xmlui.JidInputWidget, StringWidget): type = "jid" - class TextBoxWidget(xmlui.TextWidget, InputWidget): type = "textbox"