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
This commit is contained in:
Goffi 2020-05-18 23:37:04 +02:00
commit 9780bd3480
2 changed files with 24 additions and 10 deletions

View file

@ -310,17 +310,23 @@ class PubsubSchema(object):
form = data_form.Form.fromElement(x_elt) form = data_form.Form.fromElement(x_elt)
if form_ns and form.formNamespace != form_ns: if form_ns and form.formNamespace != form_ns:
continue 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( xmlui = xml_tools.dataFormResult2XMLUI(
form, form,
schema_form, schema_form,
# FIXME: conflicts with schema (i.e. if "id" or "publisher" already exists) # FIXME: conflicts with schema (i.e. if "id" or "publisher" already exists)
# are not checked # are not checked
prepend=( prepend=prepend,
("label", "id"),
("text", item_elt["id"], "id"),
("label", "publisher"),
("text", item_elt.getAttribute("publisher", ""), "publisher"),
),
filters=filters, filters=filters,
read_only=False, read_only=False,
) )

View file

@ -22,11 +22,10 @@
XMLUI classes from this modules can then be iterated to create the template XMLUI classes from this modules can then be iterated to create the template
""" """
from sat.core.log import getLogger
log = getLogger(__name__)
from sat_frontends.tools import xmlui
from functools import partial from functools import partial
from sat.core.log import getLogger
from sat_frontends.tools import xmlui
from sat_frontends.tools import jid
try: try:
from jinja2 import Markup as safe from jinja2 import Markup as safe
except ImportError: except ImportError:
@ -35,6 +34,9 @@ except ImportError:
safe = lambda x: x safe = lambda x: x
log = getLogger(__name__)
## Widgets ## ## Widgets ##
@ -119,6 +121,13 @@ class TextWidget(xmlui.TextWidget, ValueWidget):
type = "text" 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): class LabelWidget(xmlui.LabelWidget, ValueWidget):
type = "label" type = "label"
@ -137,7 +146,6 @@ class StringWidget(xmlui.StringWidget, InputWidget):
class JidInputWidget(xmlui.JidInputWidget, StringWidget): class JidInputWidget(xmlui.JidInputWidget, StringWidget):
type = "jid" type = "jid"
class TextBoxWidget(xmlui.TextWidget, InputWidget): class TextBoxWidget(xmlui.TextWidget, InputWidget):
type = "textbox" type = "textbox"