plugin XEP-0346: new psSchemaDictGet to get node schema as a serialisable dict
This commit is contained in:
parent
026ac9db13
commit
2819405d56
1 changed files with 29 additions and 0 deletions
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
from collections import Iterable
|
||||
import itertools
|
||||
from typing import Optional
|
||||
from zope.interface import implementer
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from twisted.words.protocols.jabber.xmlstream import XMPPHandler
|
||||
|
|
@ -29,6 +30,7 @@ from wokkel import generic
|
|||
from sat.core.i18n import _
|
||||
from sat.core import exceptions
|
||||
from sat.core.constants import Const as C
|
||||
from sat.core.xmpp import SatXMPPEntity
|
||||
from sat.tools import xml_tools
|
||||
from sat.tools import utils
|
||||
from sat.tools.common import date_utils
|
||||
|
|
@ -84,6 +86,14 @@ class PubsubSchema(object):
|
|||
service, nodeIdentifier, default_node=None, profile_key=profile_key),
|
||||
async_=True,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"psSchemaDictGet",
|
||||
".plugin",
|
||||
in_sign="sss",
|
||||
out_sign="s",
|
||||
method=self._getSchemaDict,
|
||||
async_=True,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"psItemsFormGet",
|
||||
".plugin",
|
||||
|
|
@ -247,6 +257,25 @@ class PubsubSchema(object):
|
|||
await self._p.createIfNewNode(client, service, node_id, node_options)
|
||||
await self._p.sendItem(client, service, node_id, schema, self._p.ID_SINGLETON)
|
||||
|
||||
def _getSchemaDict(self, service, nodeIdentifier, profile):
|
||||
service = None if not service else jid.JID(service)
|
||||
client = self.host.getClient(profile)
|
||||
d = defer.ensureDeferred(self.getSchemaDict(client, service, nodeIdentifier))
|
||||
d.addCallback(data_format.serialise)
|
||||
return d
|
||||
|
||||
async def getSchemaDict(
|
||||
self,
|
||||
client: SatXMPPEntity,
|
||||
service: Optional[jid.JID],
|
||||
nodeIdentifier: str) -> dict:
|
||||
"""Retrieve a node schema and format it a simple dictionary
|
||||
|
||||
The dictionary is made so it can be easily serialisable
|
||||
"""
|
||||
schema_form = await self.getSchemaForm(client, service, nodeIdentifier)
|
||||
return xml_tools.dataForm2dataDict(schema_form)
|
||||
|
||||
def _getDataFormItems(self, form_ns="", service="", node="", schema="", max_items=10,
|
||||
item_ids=None, sub_id=None, extra_dict=None,
|
||||
profile_key=C.PROF_KEY_NONE):
|
||||
|
|
|
|||
Loading…
Reference in a new issue