Hi,

sorry for posting again the same issue, but maybe this time
I get the description of the little problem better.

Hopefully somebody can explain me a change in recent web.py.
The following code used to work fine in web.py 0.32:


import web

template = '<form name="main" method="post">%s<input type="submit"/></form>'

urls = ('/', 'index')
app = web.application(urls, globals())

myform = web.form.Form(web.form.Checkbox('A', value=False),
                        web.form.Checkbox('B', value=True))

class index:
      def GET(self):
          form = myform()
          return template % form.render()

      def POST(self):
          form = myform()
          if not form.validates():
              return template % form.render()
          else:
              return "Results: %s, %s" % (form['A'].value, form['B'].value)

if __name__=="__main__":
      web.internalerror = web.debugerror
      app.run()


I.e. the second checkbox was checked by default and the result was
"on" or None. With web.py 0.33 this code leads to an exception:

Traceback (most recent call last):
   File "./check33.py", line 11, in <module>
     web.form.Checkbox('B', value=True))
   File "/usr/lib/pymodules/python2.5/web/form.py", line 284, in __init__
     Input.__init__(self, name, *validators, **attrs)
   File "/usr/lib/pymodules/python2.5/web/form.py", line 124, in __init__
     self.id = attrs.setdefault('id', self.get_default_id())
   File "/usr/lib/pymodules/python2.5/web/form.py", line 288, in get_default_id
     return self.name + '_' + value.replace(' ', '_')
AttributeError: 'bool' object has no attribute 'replace'

If I change myform in the following way:

myform = web.form.Form(web.form.Checkbox('A', checked=False),
                        web.form.Checkbox('B', checked=True))

the exception is gone, but the result
((form['A'].value, form['B'].value)) is always None, not the
actual states of the checkboxes.

If I change this line in the following way:

return "Results: %s, %s" % (form['A'].checked, form['B'].checked)

I always get False for the first, True for the second checkbox,
not the actual states of the checkboxes.

I'm sure I'm missing sth. trivial, but what?

Thanks in advance for any useful hint!

--

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.


Reply via email to