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 :-)
Stuart
On Apr 17, 2:39 pm, p0tat03 <[EMAIL PROTECTED]> wrote:
> Hey all,
>
> I've tried both Google and this group to no avail, as I cannot figure
> what I'm doing wrong. I am trying to populate a SingleSelectField from
> database at each page-load for a form. Below is the code I am using
> (bits excised to reduce length):
>
> class LocationFields(widgets.WidgetsList):
> locationid = widgets.HiddenField()
> customerid =
> widgets.SingleSelectField(options=Customer.build_list(field='client_name'),
> label="Customer", validator=validators.NotEmpty())
>
> location_form = widgets.TableForm(
> fields=LocationFields(),
> action="save",
> submit_text="Save"
> )
>
> class Locations:
>
> @expose(template="water.templates.adduser")
> def add(self, somemoreparams here):
> #Rebuild customer data
> location_form.fields.customerid =
> widgets.SingleSelectField(options=Customer.build_list(field='client_name'),
> label="Customer", validator=validators.NotEmpty())
> data = {'someparams': someparams}
> return dict(form=location_form, data=data)
>
> The problem here is that the list is only populating at module load,
> and not for each page load, even though I believe that when I call add
> I should be replacing the form's "customerid" field with a new
> instance?
>
> Any help appreciated :)
>
> -- Jerry
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---