I have a widget:

categories = widgets.MultipleSelectField(label='Category',
default=_get_category_defaults, options=_get_category_list,
validator=validators.NotEmpty)

which passes two callables to MultipleSelectField's constructor.
_get_category_defaults returns a list of numbers, while
_get_category_list simply returns a list of tuples. The problem is,
when I display this template, _get_category_defaults is not called,
whatsoever. I can set default to a list, for example [3, 5, 7] and when
displayed, 3, 5, and 7 are selected. This has made it near impossible
to set defaults in forms depending on the user. I have found a
work-around, defining my own widget:

class CategoryMultipleSelect(widgets.MultipleSelectField):
    def update_params(self, params):
        super(CategoryMultipleSelect, self).update_params(params)
        category_defaults = _get_category_defaults()
        if category_defaults is None:
            return
        for cat in params['grouped_options'][0][1]:
            if cat[0] in category_defaults:
                cat[2][self._selected_verb] = self._selected_verb

which hardly scales for anyones purposes if they have a lot of dynamism
in their forms. It also tightly couples you to the data you're feeding
the widget, and requires you to know a lot about the widgets API to
simply set defaults. I am not sure if I should consider this a bug, or
if anyone is aware, or if is the desired behaviour. I would appreciate
it greatly if someone could please respond on this matter so I can
either fix it, wait for it to be fixed, submit a bug report, etc

Thanks,
-Sam


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to