>From turbogears/widgets/tests/test_widgets.py:
--------------
def test_callable_options():
"""Widgets support callable options passed to the
constructor or dynamically"""
def options_func1():
return [(1, "coke"), (2, "pepsi"), (3, "redbull")]
def options_func2():
return [(1, "python"), (2, "java"), (3, "pascal")]
w = widgets.SingleSelectField(options=options_func1)
output = w.render().lower()
assert 'coke' in output
assert 'pepsi' in output
assert 'redbull' in output
# continues...
--------------
So, one idea is to have a function to hit your database and return the
list of ice cream flavors... and apply a memoize decorator ([1] or
[2]) on it...
Cheers
Roger
[1] - http://wiki.python.org/moin/PythonDecoratorLibrary
[2] - http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498110
On 11/4/06, Matt Wilson <[EMAIL PROTECTED]> wrote:
>
> I have a table of ice cream flavors, and I'm sure that the list won't
> change over time.
>
> I need to draw a form with a pulldown that lists the flavors. If at all
> possible, I don't want to hit my database on every page view in order
> to populate the pulldown.
>
> I'm thinking about generating my template by using a script to write it
> for me.
>
> Any better ideas?
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---