# HG changeset patch # User sylvain.thenault@logilab.fr # Date 1239808948 -7200 # Node ID decb7507fa916a160ef776f4eb970d0f1284df6d # Parent c558a88bb85dfaf55b7ad9a923acc34674d92057 nicer renderer options handling: can be passed to __init__ or to render diff -r c558a88bb85d -r decb7507fa91 web/formrenderers.py --- a/web/formrenderers.py Wed Apr 15 14:41:38 2009 +0200 +++ b/web/formrenderers.py Wed Apr 15 17:22:28 2009 +0200 @@ -20,24 +20,35 @@ class FormRenderer(object): """basic renderer displaying fields in a two columns table label | value """ + display_fields = None # None -> all fields + display_label = True + display_help = True + display_progress_div = True button_bar_class = u'formButtonBar' - def __init__(self, display_fields=None, display_label=True, - display_help=True, button_bar_class=None): - self.display_fields = display_fields # None -> all fields - self.display_label = display_label - self.display_help = display_help - if button_bar_class is not None: - self.button_bar_class = button_bar_class - + def __init__(self, **kwargs): + if self._set_options(kwargs): + raise ValueError('unconsumed arguments %s' % kwargs) + + def _set_options(self, kwargs): + for key in ('display_fields', 'display_label', 'display_help', + 'display_progress_div', 'button_bar_class'): + try: + setattr(self, key, kwargs.pop(key)) + except KeyError: + continue + return kwargs + # renderer interface ###################################################### def render(self, form, values): + self._set_options(values) form.add_media() data = [] w = data.append w(self.open_form(form, values)) - w(u'