OMG, i've overworked and forgot about enumerate which i'm using everywhere :))

So, enumerate returns iterator that has the end and when elements are
left and raises StopIteration, but it happens only in case of .next()
call. If iterator doesn't have elements and you apply list/tuple to it
(that is what SingleSelectField does) you'll get empty list/tuple. So,
the first page rendering moves your enumerate to the end by returning
filled list/tuple and the second (and so on) page rendering works with
ended enumerate.

In [1]: items = enumerate([1])

In [2]: items.next()
Out[2]: (0, 1)

In [3]: items.next()
---------------------------------------------------------------------------
<type 'exceptions.StopIteration'>:

In [4]: list(items)
Out[4]: []

p.s. sorry for my english :)

2011/1/20 Tamas Hegedus <[email protected]>:
> Enumerate is a built-in function of python.
> I think I used it here, since it was used this way in the tosca tutorial.
>
> I tried a simple list and it works!
>
> Thanks,
> tamas
>
> Pavel Strashkin wrote:
>>
>> Hi Tamas,
>>
>> What the "enumerate"? Is it your own type? Try to replace it with list
>> or tuple and check how it works.
>>
>> 2011/1/20 Tamas Hegedus <[email protected]>:
>>>
>>> Hi,
>>>
>>> I have a from with a single select field. At the first visit of the page
>>> the
>>> options are in the select field. Other times they are there or not. E.g.
>>> pressing the submit button with an empty textfield in the form, the form
>>> is
>>> returned, but without selectable values in the select (so the select is
>>> there, but no options).
>>>
>>> Any idea? Thanks!
>>> Tamas
>>>
>>> (not the complete code)
>>> -----------------------------
>>> class BoxForm(TableForm):
>>>
>>>   type_options = enumerate(('LN','-80C','-20C', '4C', 'RT'))
>>>
>>>   fields = [
>>>       SingleSelectField('type', options=type_options, default='LN',
>>> validator=NotEmpty),
>>>       TextField('name', validator=NotEmpty),
>>>       ...
>>>       ]
>>> create_box_form = BoxForm("create_box_form", action="newbox_post")
>>> -----------------------------
>>> (root.py)
>>>   @expose('tgmystorage.templates.newbox')
>>>   @authenticate
>>>   def newbox(self, **kw):
>>>       tmpl_context.create_box_form = create_box_form
>>>       return dict()
>>>
>>>   #**************************
>>>   @authenticate
>>>   @validate(create_box_form, error_handler=newbox)
>>>   @expose()
>>>   def newbox_post(self, **kw):
>>>       redirect(url("/browse"))
>>>
>>> --
>>> 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.
>>>
>>>
>>
>
>
> --
> Tamas Hegedus, PhD
> Membrane Research Group        | phone: (36) 1-459 1500/60233
> Hungarian Academy of Sciences  | fax:   (36) 1-266 6656
> Tuzolto utca 37-47             | mailto:[email protected]
> Budapest, 1094, Hungary        | http://www.hegelab.org
>
> --
> 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.
>
>

-- 
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.

Reply via email to