[Zope] How to use RESPONSE.redirect ?

Stuart Foster stuartafoster@home.com
Thu, 17 Aug 2000 08:14:08 -0700


Thanks for the input. I ended up putting the info I needed into the url

<dtml-var "someurl?a=blah">

I put it in a method that is usuble from a couple of forms and it seems to
work.

Thanks again.

-----Original Message-----
From: ender@earthlink.net [mailto:ender@earthlink.net]On Behalf Of Kapil
Thangavelu
Sent: Tuesday, August 15, 2000 3:44 PM
To: Stuart Foster
Cc: Zope List
Subject: Re: [Zope] How to use RESPONSE.redirect ?


Stuart Foster Wrote:
> I want to use redirect to call another form passing the current form, how
> can I do that.
>
> <dtml-call RESPONSE.redirect('otherform'+?????)>
>

Hi Stuart,

i ran into the same problem a little while ago. i was trying to pass the
user around to the proper display&process page(with inputs inplace)
after a logic page that determined where they should go based on their
inputs. IMO, The crux of the problem is that Zope as a web development
platform should include the urlparse lib from the python core more over
this problem and others like it should be remedied i believe by a
standard method of extending the modules in the _ namespace with thread
safe modules that a developer deems nesc. OK enough soap box... i ended
up reimplementing the nesc. functionality in a python method and created
another method to implement complete form insertion in much the same the
style that of some ACS(arsdigita) utiltiy methods do. here they are,
usage examples are included in the code.

of course this solution requires evan simpson's python methods product
be installed on your zope.

Cheers Kapil

<method 1 note="depends on method2">
name: url_encode_form_vars
args: namespace
<code>
# depends on url_encode_vars

try:
        vars=namespace['REQUEST'].form
        method =  namespace.getitem('url_encode_vars', 0)
        return method(vars)
except:
        pass


####
#example call to above
#<dtml-call "RESPONSE.redirect(URL1+'?'+url_encode_form_vars(_))">
</code>

</method 1>


<method 2>

name: url_encode_vars
args:

<code>

'''
Code straight from urllib minor
changes to get around assignment to sub_scripts,
access to string module, and namepace issues

expects a dictionary of key value pairs to be encoded

example call

<dtml-call
"RESPONSE.redirect(URL1+'?'+url_encode_vars({vars={'squishy':1,
'bad_input':'&user=root'}) )">
'''

global always_safe, quote, quote_plus
always_safe = _.string.letters + _.string.digits + '_,.-'

def quote(s, safe = '/'):
    global always_safe
    safe = always_safe + safe
    res = []
    for c in s:
        if c not in safe:
            res.append('%%%02x'%ord(c))
        else:
            res.append(c)
    return _.string.joinfields(res, '')


def quote_plus(s, safe='/'):
    global quote
    if ' ' in s:
        res = []
        # replaec ' ' with '+'
        l = _.string.split(s, ' ')
        for i in l:
            res.append(quote(i, safe))
        return _.string.join(res, '+')
    else:
        return quote(s, safe)


def urlencode(dict):
     global quote_plus
     l = []
     for k, v in dict.items():
         k = quote_plus(str(k))
         v = quote_plus(str(v))
         l.append(k + '=' + v)
     return _.string.join(l, '&')


return urlencode(vars)
</code>
</method 2>