mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-24 03:00:15 +00:00
x:data form improvements
This commit is contained in:
parent
e3a5211b6d
commit
f84f02acff
1 changed files with 17 additions and 12 deletions
|
@ -96,13 +96,13 @@ class Form(FieldContainer):
|
||||||
self.items = []
|
self.items = []
|
||||||
|
|
||||||
def merge(self, form2):
|
def merge(self, form2):
|
||||||
form1 = Form(self.xmpp, self.type, self.title, self.instructions)
|
form1 = Form(ftype=self.type)
|
||||||
form1.fromXML(self.getXML(self.type))
|
form1.fromXML(self.getXML(self.type))
|
||||||
for field in form2.fields:
|
for field in form2.fields:
|
||||||
if not field.var in form1.fields:
|
if not field.var in form1.field:
|
||||||
form1.addField(field.var, field.type, field.label, field.desc, field.required, field.value)
|
form1.addField(field.var, field.type, field.label, field.desc, field.required, field.value)
|
||||||
else:
|
else:
|
||||||
form1.fields[field.var].value = field.value
|
form1.field[field.var].value = field.value
|
||||||
for option, label in field.options:
|
for option, label in field.options:
|
||||||
if (option, label) not in form1.fields[field.var].options:
|
if (option, label) not in form1.fields[field.var].options:
|
||||||
form1.fields[field.var].addOption(option, label)
|
form1.fields[field.var].addOption(option, label)
|
||||||
|
@ -179,17 +179,17 @@ class Form(FieldContainer):
|
||||||
form = ET.Element('{jabber:x:data}x')
|
form = ET.Element('{jabber:x:data}x')
|
||||||
form.attrib['type'] = self.type
|
form.attrib['type'] = self.type
|
||||||
if self.title and self.type in ('form', 'result'):
|
if self.title and self.type in ('form', 'result'):
|
||||||
title = ET.Element('title')
|
title = ET.Element('{jabber:x:data}title')
|
||||||
title.text = self.title
|
title.text = self.title
|
||||||
form.append(title)
|
form.append(title)
|
||||||
if self.instructions and self.type == 'form':
|
if self.instructions and self.type == 'form':
|
||||||
instructions = ET.Element('instructions')
|
instructions = ET.Element('{jabber:x:data}instructions')
|
||||||
instructions.text = self.instructions
|
instructions.text = self.instructions
|
||||||
form.append(instructions)
|
form.append(instructions)
|
||||||
for field in self.fields:
|
for field in self.fields:
|
||||||
form.append(field.getXML(self.type))
|
form.append(field.getXML(self.type))
|
||||||
for reported in self.reported:
|
for reported in self.reported:
|
||||||
form.append(reported.getXML('reported'))
|
form.append(reported.getXML('{jabber:x:data}reported'))
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
form.append(item.getXML(self.type))
|
form.append(item.getXML(self.type))
|
||||||
#if tostring:
|
#if tostring:
|
||||||
|
@ -264,6 +264,11 @@ class FormField(object):
|
||||||
self.desc = desc
|
self.desc = desc
|
||||||
|
|
||||||
def setValue(self, value):
|
def setValue(self, value):
|
||||||
|
if self.type == 'boolean':
|
||||||
|
if value in ('1', 1, True, 'true', 'True', 'yes'):
|
||||||
|
value = True
|
||||||
|
else:
|
||||||
|
value = False
|
||||||
if self.islinebreak and value is not None:
|
if self.islinebreak and value is not None:
|
||||||
self.value += value.split('\n')
|
self.value += value.split('\n')
|
||||||
else:
|
else:
|
||||||
|
@ -299,7 +304,7 @@ class FormField(object):
|
||||||
self.setDescription(xml.find('{jabber:x:data}desc').text)
|
self.setDescription(xml.find('{jabber:x:data}desc').text)
|
||||||
|
|
||||||
def getXML(self, ftype):
|
def getXML(self, ftype):
|
||||||
field = ET.Element('field')
|
field = ET.Element('{jabber:x:data}field')
|
||||||
if ftype != 'result':
|
if ftype != 'result':
|
||||||
field.attrib['type'] = self.type
|
field.attrib['type'] = self.type
|
||||||
if self.type != 'fixed':
|
if self.type != 'fixed':
|
||||||
|
@ -309,21 +314,21 @@ class FormField(object):
|
||||||
field.attrib['label'] = self.label
|
field.attrib['label'] = self.label
|
||||||
if ftype == 'form':
|
if ftype == 'form':
|
||||||
for option in self.options:
|
for option in self.options:
|
||||||
optionxml = ET.Element('option')
|
optionxml = ET.Element('{jabber:x:data}option')
|
||||||
optionxml.attrib['label'] = option[1]
|
optionxml.attrib['label'] = option[1]
|
||||||
optionval = ET.Element('value')
|
optionval = ET.Element('{jabber:x:data}value')
|
||||||
optionval.text = option[0]
|
optionval.text = option[0]
|
||||||
optionxml.append(optionval)
|
optionxml.append(optionval)
|
||||||
field.append(optionxml)
|
field.append(optionxml)
|
||||||
if self.required:
|
if self.required:
|
||||||
required = ET.Element('required')
|
required = ET.Element('{jabber:x:data}required')
|
||||||
field.append(required)
|
field.append(required)
|
||||||
if self.desc:
|
if self.desc:
|
||||||
desc = ET.Element('desc')
|
desc = ET.Element('{jabber:x:data}desc')
|
||||||
desc.text = self.desc
|
desc.text = self.desc
|
||||||
field.append(desc)
|
field.append(desc)
|
||||||
for value in self.value:
|
for value in self.value:
|
||||||
valuexml = ET.Element('value')
|
valuexml = ET.Element('{jabber:x:data}value')
|
||||||
if value is True or value is False:
|
if value is True or value is False:
|
||||||
if value:
|
if value:
|
||||||
valuexml.text = '1'
|
valuexml.text = '1'
|
||||||
|
|
Loading…
Reference in a new issue