[Zope-Coders] Question about procedures
Florent Guillaume
fg at nuxeo.com
Thu Mar 24 12:14:33 EST 2005
A few notes:
martin f krafft <madduck at madduck.net> wrote:
> Index: TypesTool.py
> ===================================================================
> RCS file: /cvs-repository/Products/CMFCore/TypesTool.py,v
> retrieving revision 1.85
> diff -u -r1.85 TypesTool.py
> --- TypesTool.py 23 Mar 2005 21:56:09 -0000 1.85
> +++ TypesTool.py 24 Mar 2005 15:56:08 -0000
> @@ -862,12 +862,14 @@
>
> ob = info.constructInstance(container, id, *args, **kw)
>
> - if RESPONSE is not None:
> + if RESPONSE is not None and ob:
You should check 'and ob is not None' too.
But why could it be None ? What's the point (sorry I don't have context).
> + if not hasattr(ob, 'absolute_url'):
Do not use hasattr for persistent objects. Use
if getattr(ob, 'absolute_url', None) is None:
> + raise TypeError('constructInstance did not return a CMF object.')
Also, check your indentation (should be 4 chars).
> immediate_url = '%s/%s' % ( ob.absolute_url()
> , info.immediate_view )
> RESPONSE.redirect( immediate_url )
>
> - return ob.getId()
> + return getattr(ob, 'id', None)
Please don't do that, getId() is the proper API to call.
Florent
--
Florent Guillaume, Nuxeo (Paris, France) CTO, Director of R&D
+33 1 40 33 71 59 http://nuxeo.com fg at nuxeo.com
More information about the Zope-Coders
mailing list