This is an error
string
I was experimenting with the Form widgets and reading along in the Quixote
Cookbook and found either an error in the Cookbook or a bug in the Widget
code (Quixote 2.1).
It can be reproduced with: (almost verbatim from page 10 of the Cookbook
revision 0.4, output copied from my terminal screen)
$ python
Python 2.4.1 (#1, May 16 2005, 15:19:29)
[GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import quixote
>>> from quixote.form import widget
>>> x=widget.StringWidget('name',size=20)
>>> x
>>> print x.render()
Traceback (most recent call last):
File "", line 1, in ?
File "/usr/lib/python2.4/site-packages/quixote/form/widget.py", line 172,
in render
r += self.render_error(self.get_error())
File "/usr/lib/python2.4/site-packages/quixote/form/widget.py", line 96,
in get_error
self.parse(request=request)
File "/usr/lib/python2.4/site-packages/quixote/form/widget.py", line 125,
in parse
request = get_request()
File "/usr/lib/python2.4/site-packages/quixote/publish.py", line 302, in
get_request
return _publisher.get_request()
AttributeError: 'NoneType' object has no attribute 'get_request'
>>>
The problem is that widget.py imports get_request which is from the
Publisher class. In this context, there is no Publisher instance. The funny
thing, though, is that once you set an attribute of the widget, the error
goes away. For example:
python
Python 2.4.1 (#1, May 16 2005, 15:19:29)
[GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import quixote
>>> from quixote.form import widget
>>> x=widget.StringWidget('name',size=20)
>>> print x.render()
Traceback (most recent call last):
File "", line 1, in ?
File "/usr/lib/python2.4/site-packages/quixote/form/widget.py", line 172,
in render
r += self.render_error(self.get_error())
File "/usr/lib/python2.4/site-packages/quixote/form/widget.py", line 96,
in get_error
self.parse(request=request)
File "/usr/lib/python2.4/site-packages/quixote/form/widget.py", line 125,
in parse
request = get_request()
File "/usr/lib/python2.4/site-packages/quixote/publish.py", line 302, in
get_request
return _publisher.get_request()
AttributeError: 'NoneType' object has no attribute 'get_request'
>>> x.set_error('This is an error string')
>>> print x.render()
>>>
After a brief review of the code, the cause of this behavior wasn't
immediately evident to me.
For development, it would be nice to be able to use the widgets outside of a
publisher context. Any thoughts on this?
-al
Al Pacifico
Seattle, WA