On Tue, May 20, 2008 at 12:10 PM, Joe Riopel <[EMAIL PROTECTED]> wrote:
>
> On Tue, May 20, 2008 at 2:12 PM, Garland, Ken R <[EMAIL PROTECTED]> wrote:
>>
>> No problem, hope this helps:
>>
>> options_for_select: generate HTML "<option>" set. Combine into select
>> function.
>>
>> options_for_select_from_objects: same but get the labels and values
>> from specific attributes in a list of objects. Deprecate.
>>
>> options_for_select_from_dicts: same but get the labels and values from
>> specific keys in a list of dicts. Deprecate.
>
>
> Thanks for the help. I ended up just creating the following function
> in my lib\helpers.py file:
>
> def create_type_options(type_list):
> return ''.join(map(lambda ct: '<option value=\"%d\">%s</option>' %
> (ct.id, ct.name,), type_list))
>
> I am using it like this on the form:
> ${h.select('lbxType', h.create_type_options(c.type_list))}
>
>
> I tried using the options_for_select but I am assuming is using the
> __str__ method of my class, because in the drop down I see the
> following HTML:
> option value="<foobar.model.ComponentType object at
> 0x01531310>"><foobarr.model.ComponentType object at
> 0x01531310></option>
> <option value="<foobar.model.ComponentType object at
> 0x01531270>"><foobar.model.ComponentType object at
> 0x01531270></option>
>
> With my method I am seeing the following HTML, which is what I need:
> <option value="1">Operating System</option>
> <option value="2">Driver</option>
This has changed in the development version of WebHelpers, which will
be released in a couple weeks. The rails helpers are deprecated. The
new select() helper has options_for_select built into it:
# In helpers.py
from webhelpers.html.tags import *
# In the controller
c.the_options = [(LABEL, VALUE) for ...]
# List of label-value pairs. The label is shown to the user; the
value is submitted.
# Both are filtered by unicode() to produce strings. The options
can also be a regular list of
# strings or list of ints, in which case the labels will be the
same as the values.
# In the template
${h.select("fieldname", "initial value", c.the_options)}
If you're using the rails helpers, I would first make a list of
label-value pairs, give that to options_for_select, and feed the
result to select(). If your homegrown function is working there's no
reason to switch from it until you're ready to migrate to the new
helpers. However, I find join(map(lambda ...))) very hard to read.
It looks like you're essentially doing this:
def create_type_options(type_list):
options = [(ct.name, ct.id) for ct in type_list]
return options_for_select(options)
--
Mike Orr <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---