[Zope] Re: using a variable plus attribute inside a DTML-CALL

Florent Guillaume fg@nuxeo.com
4 Oct 2001 14:06:56 GMT


Mitchell L Model  <mlm@acm.org> wrote:
> >  I am constructing a URL for a redirection based on a variable 'arg' 
> >in the REQUEST.
> >  I can use that variable in a DTML-CALL, as follows (helped by 
> >discussions I found at
> >  NIP from a while ago in this list, e.g.
> > 
> >http://zope.nipltd.com/public/lists/zope-archive.nsf/242bb7cc2b2c343d802568ab003585d4/54b2a6e5a68d088980256982004fea79?OpenDocument).
> >
> >  <dtml-call
> >  expr="RESPONSE.redirect('http://www.zope.org/SiteIndex/search?text_content='
> >                          + arg)">
> >
> >  However, I want to url_quote_plus the arg.  The usual variable 
> >attribute syntax (either <dtml-var
> >  arg.url_quote_plus> or &dtml.url_quote_plus.arg;) isn't available 
> >inside the Python expression in the
> >  dtml-call.  Without creating an external method to do the quoting, 
> >how can I get the quoted version of the
> >  variable inside the Python expression?  I've tried lots of 
> >different ideas, but none worked.

url_quote_plus cannot be accessed from Python Script.

You can:
- allow urllib to be imported from python script, see mailing-list
  archives about how to allow a module to be imported

- or write an external method that does:
  import urllib
  def quote_plus(self, s):
    return urllib.quote_plus(s)

- or do it with a hack:
   - make a DTML Method called dtml_quote_plus with:
      <dtml-var s url_quote_plus>
   - and call it from python in DTML using
       dtml_quote_plus(_.None,_,s=arg)

All untested of course.


Florent

-- 
Florent Guillaume, Nuxeo SARL (Paris, France)
+33 1 40 33 79 87  http://nuxeo.com  mailto:fg@nuxeo.com