Erik Enge wrote:
Hi.
I've been browsing through the Zope and Zope-dev archives without finding anything related to this, please stop me if it has already been dealt with. :)
technical person = someone who doesn't mind fuzzing around with the manage_main pages
non-technical person = someone who needs everything in bright nice colors and would start crying if they saw the manage_main page, or anything similar.
I have a Product that allows a customer of mine to add some nice pictures (Image object) to a folder. The add-method is nice and doesn't display any horrible technical information. I wasn't very keen on making a add-method for both the technical person and the non-technical person, so I hacked the source code a bit. I changed the the lib/python/OFS/Image.py
It used to look like this:
""" def manage_addImage(self, id, file, title='', precondition='', content_type='', REQUEST=None):
[...] if REQUEST is not None: try: url=self.DestinationURL() except: url=REQUEST['URL1'] REQUEST.RESPONSE.redirect('%s/manage_main' % url) return id """
Which I changed into:
""" def manage_addImage(self, id, file, title='', precondition='', content_type='', REQUEST=None, redir=None):
[...] if redir is not None: REQUEST.RESPONSE.redirect('%s' % redir) elif REQUEST is not None: try: url=self.DestinationURL() except: url=REQUEST['URL1'] REQUEST.RESPONSE.redirect('%s/manage_main' % url) """
Now I can redirect the victim... erm.. customer to the method I want to, and they are pleased that they don't have to see the management interface.
This saves me a lot of time, since I don't have to make several add-methods, and maintainace is a more joyable happening. :)
This 'redir' thing is something I've stuck into a lot of .py files (for example, I use it in the manage_delObjects and others). And it is something I do every time a new Zope release comes out. Could this be to any use for anybody besides me? And if it could, how about adding it to the next release?
Actually, Erik, there's a "convention" in there that isn't religiously followed. The idea is that if you omit the REQUEST argument from the call, it won't redirect. So you should be able to achieve the same results just by invoking manage_addImage without including the REQUEST object. A convention I've seen that works just a little better is to redirect based on the existence of a RESPONSE object. You need RESPONSE to redirect, so if it isn't provided, you shouldn't redirect. Of course this needs to be documented and more reliable. Shane