I was talking about placing the form initialization code in __init__ , instead of duplicating it GET and POST methods.
Calling stream_form() will duplicate form too: https://github.com/webpy/webpy/blob/master/web/form.py#L29 On Nov 5, 2:38 am, Matthew Gyurgyik <[email protected]> wrote: > I understood your second method, but I don't quite follow your first method. > > Here is my code, would it be possible for you to demonstrate? My python > knowledge is not all that great.http://paste.pocoo.org/show/286281/ > > @Andrei why are the methods Justin suggest better than using > f.files.args = getMpegFiles() ? That seems pretty straight forward. From > what I understand, not much, at least Justin's second method will > completely reload the whole form every time the page loads, no? > > On 11/04/2010 07:10 PM, Justin Davis wrote: > > > > > > > > > A couple ways to do this, but nothing that's really sanctioned by the > > webpy library. First, you can reach into the form and manipulate the > > dropdown in your page handler: > > > def GET(self): > > f = stream_form() > > f.files.args = getMpegFiles() > > > And then (obviously) redo this within the POST function. You could > > also set it as an instance member and put it in the initializer to > > reduce duplication. So, something like: > > > class mypage: > > def __init__(self): > > self.form = stream_form() > > f.files.args = getMpegFiles() > > > And then just access "self.form" in your handlers. This works because, > > unlike some other web frameworks such as cherrypy, webpy initializes > > the class on each request. They aren't long running singletons. > > > The other way is to just define your form within the page handler at > > run time -- again this could go in the initializer: > > > class mypage: > > def __init__(self): > > self.form = form.Form( > > form.Dropdown( > > 'input', > > [('0','Analog Tv'),('1', 'S-Video'),('2', 'Files')], > > description="Input Source:", > > value="1", > > onchange="showChannels()" > > ), > > form.Dropdown( > > 'channels', > > channelList(), > > description="Channel:", > > value="5" > > ), > > form.Dropdown( > > 'files', > > getMpegFiles(), > > description="Files" > > ) > > ) > > > Hope that helps. > > > Cheers, > > Justin > > > On Nov 4, 3:15 pm, Pyther<[email protected]> wrote: > >> Hello > > >> Here is my code:http://paste.pocoo.org/show/286254/ > > >> Basically I have this: > > >> form.Dropdown( > >> 'files', > >> getMpegFiles(), > >> description="Files" > >> ) > > >> Where getMpegFiles() returns a list of filenames. It seems as if the > >> dropdown get rendered on the first run and then won't get updated > >> until webpy restarts. How can I force the function to be called on > >> every page load? Ideally I would like to allow users to add files to a > >> directory and then the list get updated. > > >> Thanks, > >> pyther -- You received this message because you are subscribed to the Google Groups "web.py" 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/webpy?hl=en.
