[Zope-CMF] Passing Multiple Variables Using RESPONSE.redirect

Jeffrey P Shell jeffrey@cuemedia.com
Wed, 14 Aug 2002 11:09:46 -0600


On 8/14/02 8:23 AM, "Mike Doanh Tran" <mtran@shufflemasterrd.com> wrote:

> Hi All,
> 
> Can some one please show me how to pass multiple variables using
> RESPONSE.redirect?  What I want to do is to force users to login before they
> can make any changes to a bug.  So I check to see if the user is
> authenticated, if not then I will redirect them to the login page with the
> came_from variable == to the user's requested page.  That way after they are
> login they can be redirected to their previous request with correct variables
> passed.     
> 
> dtml-call 
> expr="RESPONSE.redirect('login_form?came_from=/bugzilla/editBug?id='+bug_id)">
> 
> -bug_id is an integer.
> 
> I got the following Zope error:
> 
> Error Type: TypeError
> Error Value: cannot add type "int" to string
> 
> Does anyone have any ideas on how i can make this work?

Well yeah, you can't add an int to a string.  :)  One route is to do:

RESPONSE.redirect('....?id=' + _.str(bug_id))

To cast bug_id to a string so that it can be concatenated.

However, it's usually best in Python to use the formatted strings instead of
concatenation:

RESPONSE.redirect('....?id=%s' % bug_id)

Which will automatically do the right thing.

If you use Page Templates or Python Scripts instead, you can use the very
handy ZTUtils.make_query, which will generate a nice query string for you
(and do proper URL quoting).

In a Python Script:

 from ZTUtils import make_query

 query_string = make_query(came_from='/bugzilla/editBug?id=%s' % bug_id)
 context.REQUEST['RESPONSE'].redirect('login_form?%s' % query_string)

I've found this to lead to the path of least surprises.

-- 
Jeffrey P Shell 
www.cuemedia.com