changeset 2388:4c883d1c3e81

plugin schema: when publishing a schema, check that values of list are allowed, else use default value
author Goffi <goffi@goffi.org>
date Fri, 20 Oct 2017 08:40:54 +0200
parents a59f2abd970e
children 5675af905725
files src/plugins/plugin_exp_pubsub_schema.py
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_exp_pubsub_schema.py	Fri Oct 20 08:39:58 2017 +0200
+++ b/src/plugins/plugin_exp_pubsub_schema.py	Fri Oct 20 08:40:54 2017 +0200
@@ -285,6 +285,13 @@
                     values_list = [C.bool(v) for v in values_list]
                 elif 'jid' in field.fieldType:
                     values_list = [jid.JID(v) for v in values_list]
+            if 'list' in field.fieldType:
+                # for lists, we check that given values are allowed in form
+                allowed_values = [o.value for o in field.options]
+                values_list = [v for v in values_list if v in allowed_values]
+                if not values_list:
+                    # if values don't map to allowed values, we use default ones
+                    values_list = field.values
             field.values = values_list
 
         yield self._p.sendItem(client, service, nodeIdentifier, form.toElement(), item_id, extra)