Ńņ
(üūGc @ sS d Z d d k l Z d d Z d d d Z d d d Z d d d g Z d S(
s
Form Options Helpers
i’’’’( t html_escapec C s t | d o | i } | i n t | t t f p
| f } n g } x„ | D] } t | t t f o( | \ } } t | } t | } n | } } t | } } | | j o | i d | | f qZ | i d | | f qZ Wd i | S( s
Create select options from a container (list, tuple, dict).
Accepts a container (list, tuple, dict) and returns a string of
option tags. Given a container where the elements respond to first
and last (such as a two-element array), the "lasts" serve as option
values and the "firsts" as option text. Dicts are turned into this
form automatically, so the keys become "firsts" and values become
lasts. If ``selected`` is specified, the matching "last" or element
will get the selected option-tag. ``Selected`` may also be an array
of values to be selected when using a multiple select.
Examples (call, result)::
>>> options_for_select([["Dollar", "$"], ["Kroner", "DKK"]])
'\n'
>>> options_for_select([ "VISA", "MasterCard" ], "MasterCard")
'\n'
>>> options_for_select(dict(Basic="$20", Plus="$40"), "$40")
'\n'
>>> options_for_select([ "VISA", "MasterCard", "Discover" ], ["VISA", "Discover"])
'\n\n'
Note: Only the option tags are returned. You have to wrap this call
in a regular HTML select tag.
t valuess2 s s
( t hasattrt itemst sortt
isinstancet listt tupleR t appendt join( t containert selectedt optionst elemt namet valuet nt v( ( sA /usr/lib/python2.6/site-packages/webhelpers/rails/form_options.pyt options_for_select s$
c sZ o f d } n f d } t g } | D] } | | | q: ~ | S( s
Create select options from objects in a container.
Returns a string of option tags that have been compiled by iterating
over the ``container`` and assigning the the result of a call to the
``value_attr`` as the option value and the ``name_attr`` as the
option text.
If ``selected`` is specified, the element returning a match on
``value_attr`` will get the selected option tag.
NOTE: Only the option tags are returned. You have to wrap this call
in a regular HTML select tag.
c s t | t | f S( N( t getattr( R
( t
value_attrt name_attr( sA /usr/lib/python2.6/site-packages/webhelpers/rails/form_options.pyt make_elemO s c s
t | S( N( R ( R
( R ( sA /usr/lib/python2.6/site-packages/webhelpers/rails/form_options.pyR R s ( R ( R
R R R R t _[1]t x( ( R R sA /usr/lib/python2.6/site-packages/webhelpers/rails/form_options.pyt options_for_select_from_objects> s c sZ o f d } n f d } t g } | D] } | | | q: ~ | S( s
Create select options from dicts in a container.
Returns a string of option tags that have been compiled by iterating
over the ``container`` and assigning the result of a call to the
``value_key`` as the option value and the ``name_attr`` as the
option text.
If ``selected`` is specified, the element returning a match on
``value_key`` will get the selected option tag.
NOTE: Only the option tags are returned. You have to wrap this call
in a regular HTML select tag.
c s | | f S( N( ( R
( t name_keyt value_key( sA /usr/lib/python2.6/site-packages/webhelpers/rails/form_options.pyR h s c s | S( N( ( R
( R ( sA /usr/lib/python2.6/site-packages/webhelpers/rails/form_options.pyR k s ( R ( R
R R R R R R ( ( R R sA /usr/lib/python2.6/site-packages/webhelpers/rails/form_options.pyt options_for_select_from_dictsW s R R R N( t __doc__t webhelpers.utilR t NoneR R R t __all__( ( ( sA /usr/lib/python2.6/site-packages/webhelpers/rails/form_options.pyt