durusmail: quixote-users: Re: Form widgets usable outside context of a Publisher?
Form widgets usable outside context of a Publisher?
2005-08-15
Re: Form widgets usable outside context of a Publisher?
2005-08-15
Form widgets usable outside context of a Publisher?
2005-08-15
Form widgets usable outside context of a Publisher?
2005-08-15
Re: Form widgets usable outside context of a Publisher?
Chris Hobbs
2005-08-15
On Mon, 2005-15-08 at 09:48 -0700, Al Pacifico wrote:
> 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).
>
Yes, I fell over this behaviour but didn't spend long enough trying to
reproduce it: it went away and I felt better. I probably had, as you
suggest, added a property and caused the problem to disappear. Certainly
I feel that the Form and Widget classes should operate independently of
the Publisher.

Chris

> 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()
> 
name="name" size="20" />
This is an error > string

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