implement a get_purged() function in dataforms to send minimalist dataforms when we send a reply. fixes #4132

This commit is contained in:
Yann Leboulanger 2008-07-29 15:27:00 +00:00
parent e941ef691c
commit 8b1746140e
2 changed files with 17 additions and 1 deletions

View File

@ -386,6 +386,22 @@ class SimpleDataForm(DataForm, DataRecord):
def __init__(self, type=None, title=None, instructions=None, fields=None, extend=None):
DataForm.__init__(self, type=type, title=title, instructions=instructions, extend=extend)
DataRecord.__init__(self, fields=fields, extend=self, associated=self)
def get_purged(self):
c = SimpleDataForm(extend=self)
del c.title
c.instructions = ''
for f in c.iter_fields():
if f.required:
# Keep all required fields
continue
if (hasattr(f, 'value') and not f.value) or (hasattr(f, 'values') and \
len(f.values) == 0):
c.delChild(f)
else:
del f.label
del f.description
return c
class MultipleDataForm(DataForm):
def __init__(self, type=None, title=None, instructions=None, items=None, extend=None):

View File

@ -77,7 +77,7 @@ class SearchWindow:
if self.is_form:
self.data_form_widget.data_form.type = 'submit'
gajim.connections[self.account].send_search_form(self.jid,
self.data_form_widget.data_form, True)
self.data_form_widget.data_form.get_purged(), True)
else:
infos = self.data_form_widget.get_infos()
if infos.has_key('instructions'):