[Zope3-dev] Re:
Zope3/src/zope/app/browser/skins/debug/exceptions.py:1.1
Tres Seaver
tseaver@zope.com
12 Mar 2003 10:44:59 -0500
On Wed, 2003-03-12 at 09:43, Steve Alexander wrote:
> >>The suggestion:
> >>
> >> There's an exceptionformatter module that you might want to use:
> >>
> >> from zope.exceptions.exceptionformatter import format_exception
> >> t, v, tb = sys.exc_info()
> >> try:
> >> self.traceback = ''.join(format_exception(t, v, tb, as_html=1))
> >> finally:
> >> tb = None
> >
> >
> > Hmm, it doesn't feel right to me to have the view class do the
> > "templating" bit in its __init__. Perhaps it should just make
> > that service available to the template?
>
> I was discussing the issue of view classes doing work in __init__ with
> Jim just the other day. One problem is that some views get constructed,
> but never called. The browser menu code does this.
Actually, I'm not worried about *when* the work gets done; I'm worried
about *by whom*. A component user who wants to customize the display of
the traceback will have a much harder time doing so if the component
hard-wires its presentation by calling a black-box Python method.
This particular case is tricky, because we *don't* want to keep the
actual traceback object around for any length of time.
FWIW, in other work, I do find it a pattern that I will do lots of
adapter lookup in the __init__ of the view class, in order to make the
adapted content object easily available to the template.
Tres.
--
===============================================================
Tres Seaver tseaver@zope.com
Zope Corporation "Zope Dealers" http://www.zope.com