On Tuesday 17 April 2007 12:15, [EMAIL PROTECTED] wrote:
> I've previously found myself in a situation where the options for a
> select on my site should have been user-specific.  I therefore did
> this:
>
> preview = tfs_widgets.Image_preview_widget(
>     validator=validators.Int,
>     options=lambda: identity.current.user.preview_options,
>
> And then in my controller, before submitting the form to a template:
>
> identity.current.user.preview_options = [(movie.id, movie.file_name)
> for movie in movie_set.movies]
>
> Note that "preview_options" is not actually stored in the tg_user
> table in the DB.
>
> Seems to work well enough, although I'm open to criticism :-)

It essentially communicates over a global variable - as the user object should 
be a singleton. If two requests access this piece of code concurrenly, it 
might produce garbage.

Instead, use e.g. the cherrypy.request-object, or the possibility to pass an 
explicit option-list to the form rendering code, as Alberto has shown in his 
post.

diez

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