comparison src/plugins/plugin_exp_pubsub_schema.py @ 2421:b7e24ce97a06

plugin schema: separate lines of text-multi in different values as requested by XEP-0004
author Goffi <goffi@goffi.org>
date Sun, 05 Nov 2017 20:34:51 +0100
parents 03da3ef5fb5b
children 6c39f30444a0
comparison
equal deleted inserted replaced
2420:03da3ef5fb5b 2421:b7e24ce97a06
30 from wokkel import data_form 30 from wokkel import data_form
31 from wokkel import generic 31 from wokkel import generic
32 from zope.interface import implements 32 from zope.interface import implements
33 from collections import Iterable 33 from collections import Iterable
34 import copy 34 import copy
35 import itertools
35 36
36 NS_SCHEMA = 'https://salut-a-toi/protocol/schema:0' 37 NS_SCHEMA = 'https://salut-a-toi/protocol/schema:0'
37 38
38 PLUGIN_INFO = { 39 PLUGIN_INFO = {
39 C.PI_NAME: "PubSub Schema", 40 C.PI_NAME: "PubSub Schema",
283 if isinstance(values_list, basestring) or not isinstance(values_list, Iterable): 284 if isinstance(values_list, basestring) or not isinstance(values_list, Iterable):
284 values_list = [values_list] 285 values_list = [values_list]
285 if deserialise: 286 if deserialise:
286 if field.fieldType == 'boolean': 287 if field.fieldType == 'boolean':
287 values_list = [C.bool(v) for v in values_list] 288 values_list = [C.bool(v) for v in values_list]
289 elif field.fieldType == 'text-multi':
290 # for text-multi, lines must be put on separate values
291 values_list = list(itertools.chain(*[v.splitlines() for v in values_list]))
292
288 elif 'jid' in field.fieldType: 293 elif 'jid' in field.fieldType:
289 values_list = [jid.JID(v) for v in values_list] 294 values_list = [jid.JID(v) for v in values_list]
290 if 'list' in field.fieldType: 295 if 'list' in field.fieldType:
291 # for lists, we check that given values are allowed in form 296 # for lists, we check that given values are allowed in form
292 allowed_values = [o.value for o in field.options] 297 allowed_values = [o.value for o in field.options]