Force forms and fields to use plugin resolution
Instead of using the interface/subinterface code that was currently being implemented for the plugin. (cherry picked from commit 1467ec7)
This commit is contained in:
parent
bb094cc649
commit
0724f623bb
3 changed files with 17 additions and 14 deletions
|
@ -13,8 +13,9 @@ class FormField(ElementBase):
|
|||
namespace = 'jabber:x:data'
|
||||
name = 'field'
|
||||
plugin_attrib = 'field'
|
||||
plugin_multi_attrib = 'fields'
|
||||
interfaces = set(('answer', 'desc', 'required', 'value',
|
||||
'options', 'label', 'type', 'var'))
|
||||
'label', 'type', 'var'))
|
||||
sub_interfaces = set(('desc',))
|
||||
plugin_tag_map = {}
|
||||
plugin_attrib_map = {}
|
||||
|
@ -165,6 +166,7 @@ class FieldOption(ElementBase):
|
|||
plugin_attrib = 'option'
|
||||
interfaces = set(('label', 'value'))
|
||||
sub_interfaces = set(('value',))
|
||||
plugin_multi_attrib = 'options'
|
||||
|
||||
|
||||
FormField.addOption = FormField.add_option
|
||||
|
|
|
@ -22,8 +22,8 @@ class Form(ElementBase):
|
|||
namespace = 'jabber:x:data'
|
||||
name = 'x'
|
||||
plugin_attrib = 'form'
|
||||
interfaces = set(('fields', 'instructions', 'items',
|
||||
'reported', 'title', 'type', 'values'))
|
||||
interfaces = set(('instructions', 'items',
|
||||
'reported', 'title', 'type', ))
|
||||
sub_interfaces = set(('title',))
|
||||
form_types = set(('cancel', 'form', 'result', 'submit'))
|
||||
|
||||
|
@ -48,7 +48,7 @@ class Form(ElementBase):
|
|||
def set_type(self, ftype):
|
||||
self._set_attr('type', ftype)
|
||||
if ftype == 'submit':
|
||||
fields = self['fields']
|
||||
fields = self.get_fields()
|
||||
for var in fields:
|
||||
field = fields[var]
|
||||
del field['type']
|
||||
|
@ -74,7 +74,8 @@ class Form(ElementBase):
|
|||
field['desc'] = desc
|
||||
field['required'] = required
|
||||
if options is not None:
|
||||
field['options'] = options
|
||||
for option in options:
|
||||
field.add_option(**option)
|
||||
else:
|
||||
del field['type']
|
||||
self.append(field)
|
||||
|
@ -227,9 +228,9 @@ class Form(ElementBase):
|
|||
def set_values(self, values):
|
||||
fields = self['fields']
|
||||
for field in values:
|
||||
if field not in fields:
|
||||
if field not in self.get_fields():
|
||||
fields[field] = self.add_field(var=field)
|
||||
fields[field]['value'] = values[field]
|
||||
self.get_fields()[field]['value'] = values[field]
|
||||
|
||||
def merge(self, other):
|
||||
new = copy.copy(self)
|
||||
|
|
|
@ -11,8 +11,8 @@ class TestDataForms(SleekTest):
|
|||
|
||||
def setUp(self):
|
||||
register_stanza_plugin(Message, xep_0004.Form)
|
||||
register_stanza_plugin(xep_0004.Form, xep_0004.FormField)
|
||||
register_stanza_plugin(xep_0004.FormField, xep_0004.FieldOption)
|
||||
register_stanza_plugin(xep_0004.Form, xep_0004.FormField, iterable=True)
|
||||
register_stanza_plugin(xep_0004.FormField, xep_0004.FieldOption, iterable=True)
|
||||
|
||||
def testMultipleInstructions(self):
|
||||
"""Testing using multiple instructions elements in a data form."""
|
||||
|
@ -68,7 +68,7 @@ class TestDataForms(SleekTest):
|
|||
'value': 'cool'},
|
||||
{'label': 'Urgh!',
|
||||
'value': 'urgh'}]}
|
||||
form['fields'] = fields
|
||||
form.set_fields(fields)
|
||||
|
||||
|
||||
self.check(msg, """
|
||||
|
@ -141,13 +141,13 @@ class TestDataForms(SleekTest):
|
|||
'value': 'cool'},
|
||||
{'label': 'Urgh!',
|
||||
'value': 'urgh'}]}
|
||||
form['fields'] = fields
|
||||
form.set_fields(fields)
|
||||
|
||||
form['type'] = 'submit'
|
||||
form['values'] = {'f1': 'username',
|
||||
form.set_values({'f1': 'username',
|
||||
'f2': 'hunter2',
|
||||
'f3': 'A long\nmultiline\nmessage',
|
||||
'f4': 'cool'}
|
||||
'f4': 'cool'})
|
||||
|
||||
self.check(form, """
|
||||
<x xmlns="jabber:x:data" type="submit">
|
||||
|
@ -189,7 +189,7 @@ class TestDataForms(SleekTest):
|
|||
'value': 'cool'},
|
||||
{'label': 'Urgh!',
|
||||
'value': 'urgh'}]}
|
||||
form['fields'] = fields
|
||||
form.set_fields(fields)
|
||||
|
||||
form['type'] = 'cancel'
|
||||
|
||||
|
|
Loading…
Reference in a new issue