Mercurial > libervia-backend
comparison src/plugins/plugin_exp_pubsub_schema.py @ 2398:3ff9d7a7fe71
core (XMLUI): filters can now be used when converting data form to XMLUI:
they can be used to modify created widgets, this is specially useful to customise well known field.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 27 Oct 2017 18:06:58 +0200 |
parents | 713cedc99752 |
children | 03da3ef5fb5b |
comparison
equal
deleted
inserted
replaced
2397:7fff98d64ab5 | 2398:3ff9d7a7fe71 |
---|---|
197 return iq_elt.send() | 197 return iq_elt.send() |
198 | 198 |
199 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): | 199 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): |
200 client = self.host.getClient(profile_key) | 200 client = self.host.getClient(profile_key) |
201 service = jid.JID(service) if service else None | 201 service = jid.JID(service) if service else None |
202 if not node: | |
203 raise exceptions.DataError(_(u'empty node is not allowed')) | |
202 if schema: | 204 if schema: |
203 schema = generic.parseXml(schema.encode('utf-8')) | 205 schema = generic.parseXml(schema.encode('utf-8')) |
204 else: | 206 else: |
205 schema = None | 207 schema = None |
206 max_items = None if max_items == C.NO_LIMIT else max_items | 208 max_items = None if max_items == C.NO_LIMIT else max_items |
207 extra = self._p.parseExtra(extra_dict) | 209 extra = self._p.parseExtra(extra_dict) |
208 d = self.getDataFormItems(client, form_ns or None, service, node or None, schema, max_items or None, item_ids, sub_id or None, extra.rsm_request, extra.extra) | 210 d = self.getDataFormItems(client, form_ns or None, service, node, schema, max_items or None, item_ids, sub_id or None, extra.rsm_request, extra.extra) |
209 d.addCallback(self._p.serItemsData) | 211 d.addCallback(self._p.serItemsData) |
210 return d | 212 return d |
211 | 213 |
212 @defer.inlineCallbacks | 214 @defer.inlineCallbacks |
213 def getDataFormItems(self, client, form_ns, service, nodeIdentifier, schema=None, max_items=None, item_ids=None, sub_id=None, rsm_request=None, extra=None): | 215 def getDataFormItems(self, client, form_ns, service, nodeIdentifier, schema=None, max_items=None, item_ids=None, sub_id=None, rsm_request=None, extra=None, filters=None): |
214 """Get items known as being data forms, and convert them to XMLUI | 216 """Get items known as being data forms, and convert them to XMLUI |
215 | 217 |
216 @param form_ns (unicode, None): namespace of the form | 218 @param form_ns (unicode, None): namespace of the form |
217 None to accept everything, even if form has no namespace | 219 None to accept everything, even if form has no namespace |
218 @param schema(domish.Element, data_form.Form, None): schema of the node if known | 220 @param schema(domish.Element, data_form.Form, None): schema of the node if known |
219 if None, it will be retrieved from node | 221 if None, it will be retrieved from node |
222 @param filters(dict, None): same as for xml_tools.dataFormResult2XMLUI | |
220 other parameters as the same as for [getItems] | 223 other parameters as the same as for [getItems] |
221 @return (list[unicode]): XMLUI of the forms | 224 @return (list[unicode]): XMLUI of the forms |
222 if an item is invalid (not corresponding to form_ns or not a data_form) | 225 if an item is invalid (not corresponding to form_ns or not a data_form) |
223 it will be skipped | 226 it will be skipped |
224 """ | 227 """ |
233 if form_ns and form.formNamespace != form_ns: | 236 if form_ns and form.formNamespace != form_ns: |
234 continue | 237 continue |
235 xmlui = xml_tools.dataFormResult2XMLUI( | 238 xmlui = xml_tools.dataFormResult2XMLUI( |
236 form, | 239 form, |
237 schema_form, | 240 schema_form, |
238 prepend = (('label', 'id'),('text', item_elt['id'], u'id')) | 241 prepend = (('label', 'id'),('text', item_elt['id'], u'id')), |
242 filters = filters, | |
239 ) | 243 ) |
240 items_xmlui.append(xmlui) | 244 items_xmlui.append(xmlui) |
241 break | 245 break |
242 defer.returnValue((items_xmlui, metadata)) | 246 defer.returnValue((items_xmlui, metadata)) |
243 | 247 |