diff options
author | Yann Leboulanger <asterix@lagaule.org> | 2008-07-29 19:27:00 +0400 |
---|---|---|
committer | Yann Leboulanger <asterix@lagaule.org> | 2008-07-29 19:27:00 +0400 |
commit | 8b1746140ef57eba938f3424ac8c5379d67dda0f (patch) | |
tree | 31b46860b7226f0087a6a39d87b1e05042b9bd1d /src/common/dataforms.py | |
parent | e941ef691c013a9872c3634295c693854c7d5bd9 (diff) |
implement a get_purged() function in dataforms to send minimalist dataforms when we send a reply. fixes #4132
Diffstat (limited to 'src/common/dataforms.py')
-rw-r--r-- | src/common/dataforms.py | 16 |
1 files changed, 16 insertions, 0 deletions
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): |