From 8b1746140ef57eba938f3424ac8c5379d67dda0f Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Tue, 29 Jul 2008 15:27:00 +0000 Subject: implement a get_purged() function in dataforms to send minimalist dataforms when we send a reply. fixes #4132 --- src/common/dataforms.py | 16 ++++++++++++++++ src/search_window.py | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/common/dataforms.py b/src/common/dataforms.py index 0b59d7471..01c1e93d2 100644 --- a/src/common/dataforms.py +++ b/src/common/dataforms.py @@ -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): diff --git a/src/search_window.py b/src/search_window.py index df7af6ce7..a08f3d8de 100644 --- a/src/search_window.py +++ b/src/search_window.py @@ -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'): -- cgit v1.2.3